Jump to content

simple restart function for your script(s)


Sven
 Share

Recommended Posts

Func _restart_script()
    $file = FileOpen(@TempDir & "\restart.cmd", 2)
    FileWrite($file, ':LOOP' & @CRLF & _
            'TaskList|Find "' & @ScriptName & '" > NUL || If Errorlevel 1 Goto CONTINUE' & @CRLF & _
            'Goto LOOP' & @CRLF & _
            ':CONTINUE' & @CRLF & _
            'start ' & '"" ' & '"' & @AutoItExe & '"' & @CRLF)
    FileClose($file)
    ShellExecute(@TempDir & "\restart.cmd", "", "", "", @SW_HIDE)
EndFunc   ;==>_restart_script

Tested to work on Win7 x64.

Function creates a batch file that when executed

- waits for your compiled script to exit

- launches your script

Here's an example of how to use it:

If FileExists("restart.cmd") Then FileDelete(@TempDir & "\restart.cmd"); for cleanup purposes

MsgBox(0, "test", "hi" & @CRLF & @ScriptName)
_restart_script()

While 1
    Sleep(100)
WEnd

Func _restart_script()
    $file = FileOpen(@TempDir & "\restart.cmd", 2)
    FileWrite($file, ':LOOP' & @CRLF & _
            'TaskList|Find "' & @ScriptName & '" > NUL || If Errorlevel 1 Goto CONTINUE' & @CRLF & _
            'Goto LOOP' & @CRLF & _
            ':CONTINUE' & @CRLF & _
            'start ' & '"" ' & '"' & @AutoItExe & '"' & @CRLF)
    FileClose($file)
    ShellExecute(@TempDir & "\restart.cmd", "", "", "", @SW_HIDE)
EndFunc   ;==>_restart_script

Click the "ok" button, then close the script via its icon in the tray.

To exit without restarting, wait for the message box to appear, then kill the compiled script via its tray icon while the message bo is still being displayed.

Changelog:

Fixed the function not restarting the script when path and / or filename contain spaces.

Edited by Sven
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...