Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access instantiated object from process ID

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
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.
 
Or perhaps a better way of putting it:

How do I expose com properties from the process ID?

Thanks

A.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top