用VBS来当本地进程没有某个程序后就重启电脑

来源:百度知道 编辑:UC知道 时间:2024/06/21 23:18:05
我是的VBS的垃圾,希望那位大哥帮忙?我是想当这个程序(用来输入机器号的)主要的功能就是当他(用来输入机器号的程序)退出时就重启电脑

将以下代码中的 你的进程名.exe 改成你自己的那个程序的进程名,另外这个VBS脚本每隔10秒钟检查一次进程,如果没有该进程名就会重启计算机!

strComputer = "."
Set wbemServices = Getobject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.execquery("select * from Win32_Process where caption='你的进程名.exe'")
Do While wbemobjectset.count <> 0
WScript.Sleep 10000
Set wbemObjectSet = wbemServices.execquery("select * from Win32_Process where caption='你的进程名.exe'")
Loop
DownFlag=6
set win32_OS=getobject("winmgmts:{(Shutdown)}//./root/cimv2").execQuery("select * from win32_operatingsystem where primary=true")
for each OS in win32_OS
OS.win32shutdown(DownFlag)
next
set win32_OS=nothing