我有以下VBscript,一旦它在任务列表中看到进程,就会杀死IE并在Kiosk模式下重新启动它。 它看起来像代码第一次通过,并启动IE,但在此之后它不会杀死/启动IE。
我的循环有问题吗? 提前谢谢。
'SCRIPT purpose: Reset IE into Kiosk mode once Screensaver comes on.
'UPDATED: 02/06/18
OPTION EXPLICIT
DIM strComputer,strProcess,strProcess2, restartFlag
DIM oshell : set oShell = CreateObject("WScript.Shell")
strComputer = "." ' local computer
strProcess = "SnapSCR.scr"
restartFlag = true
DO While true
IF isProcessRunning(strComputer,strProcess) THEN
IF restartFlag = true THEN
oShell.Run "taskkill /im iexplore.exe",, True
oShell.Run "iexplore.exe -k",,True
restartFlag = false
ELSE
restartFlag = false
End if
ELSE
restartFlag = true
END IF
WScript.Sleep 10000
LOOP
' Function to check if a process is running
FUNCTION isProcessRunning(BYVAL strComputer,BYVAL strProcessName)
DIM objWMIService, strWMIQuery
strWMIQuery = "Select * from Win32_Process where name like '" & strProcessName & "'"
SET objWMIService = GETOBJECT("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
IF objWMIService.ExecQuery(strWMIQuery).Count > 0 THEN
isProcessRunning = TRUE
ELSE
isProcessRunning = FALSE
END IF
END FUNCTION
答案 0 :(得分:0)
希望这个vbscript可以做到这一点:
Option Explicit
Dim ScreenSaverName
ScreenSaverName = "SnapSCR.scr"
If AppPrevInstance() Then
MsgBox "There is an instance already in progress" & vbCrlf &_
CommandLineLike(WScript.ScriptName),VbExclamation,_
"There is an instance already in progress"
WScript.Quit
Else
Do
Call CheckProcess(DblQuote(ScreenSaverName))
Call Pause(10)
Loop
End If
'**************************************************************************
Sub CheckProcess(ProcessPath)
Dim strComputer,objWMIService,colProcesses,WshShell,Tab,ProcessName
strComputer = "."
Tab = Split(ProcessPath,"\")
ProcessName = Tab(UBound(Tab))
ProcessName = Replace(ProcessName,Chr(34),"")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '"& ProcessName & "'")
If colProcesses.Count > 0 Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "taskkill /im iexplore.exe",0,True
WshShell.Run "iexplore.exe -k",1,True
Else
Exit Sub
End if
End Sub
'**************************************************************************
'Function to add double quotes in a variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************
Sub Pause(NSeconds)
Wscript.Sleep(NSeconds*1000)
End Sub
'**************************************************************************
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptName))
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************