| Option Explicit | | | | Main | | Sub Main() | | Dim sExeName, sExePath, sSql | | sExeName = "cmd.exe" | | sExePath = "C:\windows\system32\cmd.exe" | | | | sSql = "Select * From Win32_Process Where Name='{P1}' And CommandLine Like '%{P2}%'" | | sExePath = Replace(sExePath,"\","\\") | | sSql = Replace(sSql,"{P1}",sExeName) | | sSql = Replace(sSql,"{P2}",sExePath) | | | | Dim wim, wso, fso, n | | Set wim = GetObject("winmgmts:") | | Set wso = CreateObject("WScript.Shell") | | Set fso = CreateObject("Scripting.filesystemobject") | | | | Do While n < 2 | | If Not fso.FileExists(sExePath) Then Exit Do | | If wim.ExecQuery(sSql).Count = 0 Then | | n = n + 1 | | If n = 2 Then | | wso.Run sDoCmd, 1, True | | End If | | wso.Run """" & sExePath & """", 1, False | | Else | | Exit Do | | End If | | WScript.Sleep 50 * 1000 | | Loop | | | | End SubCOPY |
首先,求解第9行Sql代码中的P1和P2需要替换内容吗?
其次,求解第26行“wso.Run """" & sExePath & """", 1, False”是什么意思?
关于代码的改进需求:
用处:学校机房内,电子教室软件学生端,经常被学生结束进程。
需求:现在需要一个开机自启,自动检测电子教室进程运行状态,如果电子教室进程没有运行,则重启该进程(开机后该进程一直在后台运行),如果该进程第三次被检测到没有运行,则直接重启电脑 |