Reputation: 2071
I have visual basic script that among other things creates IE instance, hides it, manipulates it and then make it visible to the user.
Unfortunately, the restore function does not work on all PCs for unclear reason. The current code is:
objectIE.Visible = True
wshShell.AppActivate objectIE 'which is I think wrong as objectIE is not PID.
wscript.sleep timoutSleep
wshShell.SendKeys restWindow 'which is "% r" and will not work on all locales :(
I think the problem is in this line:
wshShell.AppActivate objectIE
I think here I need to pass PID to the AppActivate
method.
Question: How to get PID of the IE object? or wshShell.AppActivate objectIE
is correct and I'm looking in a wrong direction?
P.S. I can't use the application's title as it is not unique :(
Upvotes: 0
Views: 2327
Reputation: 1639
You can call Win32 methods from PowerShell script using pInvoke. Examples of this all over the interwebs. For PostMessage there's an example here: SendMessage is causing script to hang
For this to work you would need to build up the lines of PSScript in a string and then execute it using e.g.
powershell.exe -ExecutionPolicy Unrestricted -command "get-process -Name iexplore"
And extract the resulting Ids, then send it to the script that calls PostMessage()
, or even put all the commands into a single (short) script.
Upvotes: 1