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
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