我一直有问题让重要的应用程序一直在运行。我尝试制作一个脚本来监视它何时关闭,记录它并尝试将其恢复。然而我的脚本说这个应用程序即使在它关闭时也在运行,而不是在任务管理器细节中列出。 (Windows 10)我如何让它工作?
'~ Create a FileSystemObject
Set objFSO=CreateObject("Scripting.FileSystemObject")
'~ Provide file path
outFile="C:\" & Day(Date) & "-" & Month(Date) & "-" & Year(Date) & "_" & Hour(Now) & "-" & Minute(Now) & "-" & Second(Now) & "_Results.txt"
'~ Setting up file to write
Set objFile = objFSO.CreateTextFile(outFile,True)
strComputer = "."
strProcess = "CheckInNet.exe"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set WshShell = WScript.CreateObject("WScript.Shell")
Command = "C:\Program Files\Procare\Client\CheckInNet.exe"
Function IsProcessRunning( strComputer, strProcess )
Dim Process, strObject
strObject = "winmgmts://" & strComputer
count = 0
IsProcessRunning = False
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
count = count + 1
wscript.echo "check: " & IsProcessRunning
'Exit Function
End If
Next
wscript.echo "check: " & IsProcessRunning & ". # of proccesses detected: " & count
End Function
If IsProcessRunning(".",strProcess) = False Then
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " 1st check is down"
Else
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & "1st check is UP"
End IF
While (true)
If IsProcessRunning(".",strProcess) = False Then
stringDate=Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) 'generate Date
wscript.echo stringDate & " DOWN"
'~ Write to file
objFile.WriteLine stringDate & " DOWN"
wscript.Sleep(12000)
If IsProcessRunning(".",strProcess) = False Then
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " Attempting to open"
WshShell.Run Command 'attempt to re open it
wscript.Sleep(20000)
If IsProcessRunning(".",strProcess) = False Then
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " Still Down"
Else
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " UP"
End IF
Else
objFile.WriteLine Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) & " Came up on own"
End If
End If
wscript.Sleep(900)
Wend
objFile.Close
在任务管理器详细信息(适用于所有用户)中运行时,该程序称为CheckInNet.exe,并且在其安装文件夹中名称相同。如果我将CheckInNet.exe换成另一个程序,如cmd.exe,该程序工作正常。但CheckInNet.exe始终显示一个进程正在运行。请帮忙,为什么会这样做?