Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fuss:vbscript [2018/01/12 08:33] (current)
office created
Line 1: Line 1:
 +====== 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.
 +
 +<file vbscript 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
 +
 +</​file>​
 +
 +Given that the script would be placed at ''​C:​\Windows\System32\restartShell.vbs'',​ then an example invocation would be:
 +<code dos>
 +C:​\Windows\System32\wscript.exe C:​\Windows\System32\restartShell.vbs C:​\Windows\System32\notepad.exe
 +</​code>​
 +
 +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.
  

fuss/vbscript.txt ยท Last modified: 2018/01/12 08:33 by office

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.