Process Restarter

The following script can be used to start a process and, upon termination, prompt the user with a system-wide modal whether the process should be restarted.

restartShell.vbs
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''  Copyright (C) Wizardry and Steamworks 2018 - License: GNU GPLv3      ''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If WScript.Arguments.Count = 0 then
    WScript.Echo "Missing parameters"
    WScript.Quit 1
End If
 
Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
If Not fileSystemObject.FileExists(WScript.Arguments.Item(0)) Then
    WScript.Echo "File not found"
    WScript.Quit 1
End If
 
args = """" & WScript.Arguments.Item(0) & """"
i = 1
Do While i < WScript.Arguments.Count
    args = args  & " " & WScript.Arguments.Item(i)
    i = i + 1
Loop
 
Set WshShell = CreateObject("WScript.Shell")
Do While True
    WshShell.Run "" & args & "", 1, True
    If MsgBox("Restart shell?", vbYesNo + vbQuestion + vbSystemModal, "Choose options") = vbNo Then
        WScript.Quit 0
    End If
Loop

Given that the script would be placed at C:\Windows\System32\restartShell.vbs, then an example invocation would be:

C:\Windows\System32\wscript.exe C:\Windows\System32\restartShell.vbs C:\Windows\System32\notepad.exe

such that when notepad.exe terminates, the script will prompt whether to restart the program.

The script also takes care to pass all command line arguments on thereby allowing commands to be executed with parameters.