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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Activate Application by PID - doesn't work if app is in system tray.

Status
Not open for further replies.

kramerica

Technical User
Jun 19, 2001
74
0
0
US
I have an application that I want to do 2 things with.
a.) Select it and Send keystrokes.

Note After you send keystrokes to the application the window name changes from "Ready" to "Not Ready".

When the application is running my script works fine.

If I enable the application to minimize the the system tray then it doesn't work. :(

The script doesn't appear to be able to appactivate by window name if in the system tray.

How can I select this currently running application and send keystrokes to it?

'Step 1 - see if the application is listed and running.

sProcessName = "agent.exe"


strComputer = "localhost"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where " _
& "Name = '"& sProcessName & "'")

if colProcessList.count > 0 then
For Each objProcess in colProcessList
s = s & objProcess.Name & ", " & objProcess.ProcessID _
& vbNewline
Next


'Display a list of applications that are running.
' wsh.echo s


'Attempt activate the application.

'Dim WshShell, oCalc
set WshShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 500
WshShell.AppActivate "Not Ready"

'Send the Keystrokes Control+W (Not ready)
WScript.Sleep 100
WshShell.SendKeys ("^" + "w")

'Now close the routine.
Set WshShell = Nothing

else
wsh.echo "Process: ", sProcessName, " does not appear to be running."
end if
 
I would highly recommend looking at AutoIt for this instead of VBScript.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
It was my understanding that vbscript does not support the system tray.


David.
 
I managed to do this with Autoit.

I found a script that had the ability to reference .exe name regardless of the window title.

It also had functions that could access the .EXE even if it was on the system tray.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top