我正在运行以下 vbs 脚本,
set service = GetObject ("winmgmts:")
for Process in Service.Instanceof ("Win32_Process")
If Process.Name = "notepad.exe" then
Wscript.echo "Notepad running"
Wscript.quit
End If
next
Wscript.echo "notepad not running"
如果它运行则显示,如果它不运行则Notepad running
显示。Notepad not running
但是,我需要这个程序循环直到记事本关闭。一旦记事本关闭,它需要打开一个文件run.bat
注意:仅当记事本关闭时才需要运行,run.bat
如果记事本未关闭,则需要继续检查直到关闭(在后台)
请大家帮帮我...非常感谢...提前..
答案1
当传输代码时你应该小心谨慎 - 存在一些缺陷。
这个 vbscript 应该执行以下操作:
set service = GetObject ("winmgmts:")
Function IsAppRunning(AppName)
for Each Process in Service.Instancesof("Win32_Process")
If UCase(Process.Name) = UCase(AppName) then
IsAppRunning = True
Exit function
End If
next
IsAppRunning = False
End Function
AppName = "notepad.exe"
' initial test
If IsAppRunning(AppName) then
Wscript.echo AppName & " running - waiting for it to exit"
else
Wscript.echo AppName & " not running - exiting"
Wscript.quit
End If
Do while IsAppRunning(AppName)
Wscript.Sleep(1000) 'wait miliseconds
Loop
Wscript.echo AppName & " exited, do your task"
' Reaching here AppName had been running - but no more.
'
' open or run "run.bat"