VBScript - How to make program wait until process has finished?

后端 未结 4 1402
深忆病人
深忆病人 2020-12-02 01:54

I have a problem in a VBScript that I am using with a VBA/Excel macro and a HTA. The problem is just the VBScript, I have the other two components, i.e. the VBA macro and HT

4条回答
  •  我在风中等你
    2020-12-02 02:21

    This may not specifically answer your long 3 part question but this thread is old and I found this while searching today. Here is one shorter way to: "Wait until a process has finished." If you know the name of the process such as "EXCEL.EXE"

    strProcess = "EXCEL.EXE"    
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '"& strProcess &"'")
    Do While colProcesses.Count > 0
        Set colProcesses = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = '"& strProcess &"'")
        Wscript.Sleep(1000) 'Sleep 1 second
       'msgbox colProcesses.count 'optional to show the loop works
    Loop
    

    Credit to: http://crimsonshift.com/scripting-check-if-process-or-program-is-running-and-start-it/

提交回复
热议问题