使用VB脚本关闭Internet Explorer后,如何重新启动它

JukEboX

我正在寻找一个VB脚本,如果IE关闭,该脚本将自动为正在使用的信息亭重新启动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
'**************************************************************************

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

重新启动后,Internet Explorer代理不遵循异常

如何在后台运行 Python 脚本并在崩溃后重新启动它?

如何使用重新启动管理器在Inno Setup卸载中关闭然后重新启动explorer.exe?

关闭程序后如何自动重新启动程序

使用 pygame.quit() 关闭后的 Python Pygame 我无法在不停止整个脚本并重新启动它的情况下再次打开它

使用Jack后如何重新启动Alsa / PulseAudio

python 脚本关闭并重新启动后如何恢复子进程?

如果我使用“python -m”运行它,如何重新启动我的 Python 脚本?

重新启动交换后关闭问题

重新启动后恢复Bash脚本

重新启动后Powershell恢复脚本

为什么SparkContext随机关闭,如何从Zeppelin重新启动它?

使用ssh命令执行重新启动后关闭连接

使用UPSTART失败一秒钟后,如何重新启动python脚本?

使用UPSTART失败一秒钟后,如何重新启动python脚本?

如果 R 脚本的执行被中断,如何自动重新启动它的执行

如何使用批处理文件重新启动explorer.exe

如何使用批处理文件安全地重新启动explorer.exe

一旦使用StreamWriter,我将如何重新启动它?

我关闭机器电源,然后它重新启动

如何以编程方式关闭节点程序并在不使用任何库的情况下重新启动它?

如何检测Linux关闭/重新启动

如何从终端关闭或重新启动?

重新启动然后使用bash脚本关闭?

崩溃后重新启动后,Kafka如何识别组中的使用者

无法使用Internet Explorer第二次启动JavaFX Web应用(重新启动)

重新启动计算机后如何继续执行脚本?

如何使服务器上运行的Python脚本在连接断开后自动重新启动?

使用Excel VBA重新启动explorer.exe