使用VBScript激活具有已知进程ID的正在运行的进程

时间:2014-12-29 19:37:14

标签: vbscript

我的应用程序的进程ID已经在运行。 现在我想用VBScript通过这个进程id激活同一个窗口。

假设mypid是进程ID

Set Shell = CreateObject("WScript.Shell")
Shell.AppActivate(mypid)

这将在Windows 7上返回false

如果有人有答案,我想知道。

1 个答案:

答案 0 :(得分:3)

检查此链接: WshShell.AppActivate doesn't seem to work in simple vbs script

这是好的解决方案的摘要:

Set WshShell = CreateObject("WScript.Shell")
    for i=0 to 300    'this loop will continue about 30 sec if this not enough increase this number
        Rtn=WshShell.AppActivate(myPID)  'have to be the windows title of application or its process ID
        If Rtn = True Then 
            WshShell.SendKeys "......."                                  ' send key you like
            wscript.sleep 100                ' stop execute next line until finish close app
             End If 
        wscript.sleep 100
    Next