使用 VB 脚本关闭后如何重新启动 Internet Explorer
How can I relaunch Internet Explorer after it is closed using VB Script
我正在寻找一个 VB 脚本,如果 IE 关闭,它会自动为我正在使用的 Kiosk 重新启动 Internet Explorer。这是较旧的脚本,但不再有效
Set WshShell = CreateObject("WScript.Shell")
Do While True
WshShell.Run """<the path to the executable file>""", 1, True
Loop
此代码的问题在于它不断循环打开 IE。
我无法在注册表中使用 "NoBrowserClose",因为它会阻止登录 Sharepoint 网站,而这是一项要求。
这个 vbscript 可以解决问题,试试看吧:
Option Explicit
Dim ProcessPath,KioskMode
ProcessPath = "%ProgramFiles%\Internet Explorer\iexplore.exe"
KioskMode = " -K"
'Exit if the script is already running.
If AppPrevInstance() Then
MsgBox "There is an existing proceeding",VbExclamation,"There is an existing proceeding"
WScript.Quit
Else
Do
Call Main(Array(ProcessPath))
Call Pause(1) 'Sleep for 1 minute
Loop
End If
'**************************************************************************
Sub Main(colProcessPaths)
Dim ProcessPath
For Each ProcessPath In colProcessPaths
CheckProcess(ProcessPath)
Next
End Sub
'**************************************************************************
Sub CheckProcess(ProcessPath)
Dim ProcessName : ProcessName = StripProcPath(ProcessPath)
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE Commandline LIKE " & CommandLineLike(ProcessName))
If .Count = 0 Then
With CreateObject("WScript.Shell")
.Run DblQuote(ProcessPath) & KioskMode
End With
Else
Exit Sub
End if
End With
End With
End Sub
'**************************************************************************
'Checks whether a script with the same name as this script is already running
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Sub Pause(Minutes)
Wscript.Sleep(Minutes*1000*60)
End Sub
'**************************************************************************
Function StripProcPath(ProcessPath)
Dim arrStr : arrStr = Split(ProcessPath, "\")
StripProcPath = arrStr(UBound(arrStr))
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
'Function to add the double quotes into a variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************
我正在寻找一个 VB 脚本,如果 IE 关闭,它会自动为我正在使用的 Kiosk 重新启动 Internet Explorer。这是较旧的脚本,但不再有效
Set WshShell = CreateObject("WScript.Shell")
Do While True
WshShell.Run """<the path to the executable file>""", 1, True
Loop
此代码的问题在于它不断循环打开 IE。
我无法在注册表中使用 "NoBrowserClose",因为它会阻止登录 Sharepoint 网站,而这是一项要求。
这个 vbscript 可以解决问题,试试看吧:
Option Explicit
Dim ProcessPath,KioskMode
ProcessPath = "%ProgramFiles%\Internet Explorer\iexplore.exe"
KioskMode = " -K"
'Exit if the script is already running.
If AppPrevInstance() Then
MsgBox "There is an existing proceeding",VbExclamation,"There is an existing proceeding"
WScript.Quit
Else
Do
Call Main(Array(ProcessPath))
Call Pause(1) 'Sleep for 1 minute
Loop
End If
'**************************************************************************
Sub Main(colProcessPaths)
Dim ProcessPath
For Each ProcessPath In colProcessPaths
CheckProcess(ProcessPath)
Next
End Sub
'**************************************************************************
Sub CheckProcess(ProcessPath)
Dim ProcessName : ProcessName = StripProcPath(ProcessPath)
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE Commandline LIKE " & CommandLineLike(ProcessName))
If .Count = 0 Then
With CreateObject("WScript.Shell")
.Run DblQuote(ProcessPath) & KioskMode
End With
Else
Exit Sub
End if
End With
End With
End Sub
'**************************************************************************
'Checks whether a script with the same name as this script is already running
Function AppPrevInstance()
With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\.\root\cimv2")
With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _
" AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'")
AppPrevInstance = (.Count > 1)
End With
End With
End Function
'**************************************************************************
Sub Pause(Minutes)
Wscript.Sleep(Minutes*1000*60)
End Sub
'**************************************************************************
Function StripProcPath(ProcessPath)
Dim arrStr : arrStr = Split(ProcessPath, "\")
StripProcPath = arrStr(UBound(arrStr))
End Function
'**************************************************************************
Function CommandLineLike(ProcessPath)
ProcessPath = Replace(ProcessPath, "\", "\")
CommandLineLike = "'%" & ProcessPath & "%'"
End Function
'**************************************************************************
'Function to add the double quotes into a variable
Function DblQuote(Str)
DblQuote = Chr(34) & Str & Chr(34)
End Function
'**************************************************************************