INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Access instantiated object from process ID

Access instantiated object from process ID

(OP)
Hi,

I'm writing an automation script that launches various IE windows with different URL's pointing to monitoring applications.

Some of these applications require logins and setting to specific pages. These are passed from an XML file. I have achieved this by executing a AutoHotKey script. Unfortunatly, one of these websites does not have any tab index so I need to use the HTML document object to get to the right page. Normally, I'd call this when I instantiate the InternetExplorer.Application object, however my current script model does not allow for this.

So the main script instantiates an instance of InternetExplorer.Application:

CODE

[xml]$xml = Get-Content "config.xml"

function launchIE($intScreen){
$screen = $screens.screen | ? {$_.ID -eq $intScreen}
$oIE = New-Object -Com InternetExplorer.Application
$oIE.visible = $true
$oIE.navigate($screen.navigate)
while ($oIE.busy){
	sleep -Milliseconds 2000
}
$oIE.width = $screen.width 
$oIE.height = $screen.height 
$oIE.Top = $screen.top 
$oIE.Left = $screen.left 
$oIE.AddressBar = $false
$oIE.ToolBar = $false
$oIE.MenuBar = $false
$oIE.StatusBar = $false
$oIE.Refresh() # Used to refresh page so it has the "true" page title.
while ($oIE.busy){
		$iSleep = [int]$screen.runApp.postLaunchDelay
		sleep -Milliseconds $iSleep #Delay to make sure AutoHotKey has the time to run.
}
execApp
} 

And execApp looks like:

CODE

function execApp(){
Write-Host ""
Write-Host "Execute = " $screen.runApp.EXEC
Write-Host "Post Launch Delay = " $iSleep
if ($screen.runApp.EXEC -eq "1") {
 	if ($screen.runApp.args -eq "") {
 		Start-Process -FilePath $screen.runApp.path -WindowStyle $screen.runApp.windowStyle
 	}else{
 	 	Write-Host "File Path = " $screen.runApp.path
		Write-Host $("Has Argument = True " + $scriptPath +"\"+ $screen.runApp.args)
		Write-Host "Window Style = " $screen.runApp.windowStyle
		Start-Process -FilePath $screen.runApp.path -ArgumentList $($scriptPath +"\"+ $screen.runApp.args) -WindowStyle $screen.runApp.windowStyle
		}
 	
	#This is a workaround to minimise the ICA window as WFICA32.exe ignores "-WindowStyle".
 	if ($screen.runApp.publishedApp -eq "1") {
		$arg2 = $screen.windowTitle + " " + $screen.runApp.windowStyle
		Start-Process -FilePath $($scriptPath +"\Automation\WindowStyle.exe") -ArgumentList $arg2 #sets the window to Minimized, Maximized or None.
 	}
 }

$iSleep = [int]$screen.runApp.postLaunchDelay
Sleep -Milliseconds $iSleep
} 

I would like execApp to call an external ps1 file that can "access" the members of $oIE, based on the process ID. Something like (Psudo):

Main Script

CODE

$procID = oIE.ProcessID 

External Script:

CODE

$oIE2 = get-object $oIE | ? $procID -eq $oIE.ProcessID
$oIE2 | gm 

This would result in the same members available to both $oIE and $oIE2.

I've tried passing oIE object as a parameter from the main script to the external script but I cannot access it once the main script executes:

Main script calls:

CODE

powershell.exe extScript.ps1 -objIE $oIE 

extScript.ps1 looks like:

CODE

Param (
$objIE
)

$objIE.Document.nameProp
$windowTitle = $objIE.Document.nameProp
Write-Host "Windows Title: " $windowTitle 

Once the main script has finished from the powershell prompt, $oIE | gm results in:
Get-Member : The following exception occurred while retrieving the string representation for property "Application" : "The RPC Server is unavailable.

If anyone can suggest a way that I might be able to get this to work, I'd be most grateful if you'd be able to share.

Many thanks

W.

RE: Access instantiated object from process ID

(OP)
Or perhaps a better way of putting it:

How do I expose com properties from the process ID?

Thanks

A.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close