VBScript /w AppActivate for multiple instances of an application -


we have application minimize top-left corner of screen when disconnect vmware view desktop. wrote following vbs activate app , maximize works fine.

set objshell = createobject("wscript.shell")  objshell.appactivate "notepad"  objshell.sendkeys "% r"  objshell.sendkeys "% x" 

but users have multiple instances of same app open. i'm wondering how script execute every instance of application? i'm assuming i'll have key off of pid, since each instance have own pid, i'm unsure how this.

thanks, brian

appactivate accepts pid. use wmi retrieve pids of processes name.

option explicit  dim shell, wmi, wql, process  set shell = createobject("wscript.shell") set wmi = getobject("winmgmts:{impersonationlevel=impersonate}!\\.\root\cimv2")  wql = "select processid win32_process name = 'notepad.exe'"  each process in wmi.execquery(wql)     shell.appactivate process.processid     shell.sendkeys "% r"     shell.sendkeys "% x" next 

also see the win32_process class documentation.


Comments

Popular posts from this blog

pentaho - Carte Status / Kettle Slave Server Status page shows status for random runs instead of the latest run -

R summary function in ddply (plyr) in a simple way -

c# - Are delegates created via lambda expressions guaranteed to be cached? -