Sign in to follow this  
Followers 0
Sven

simple restart function for your script(s)

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



Here's a 'restart snippet' I've added to a couple of my scripts - Re-Start your Program


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Yeah, that's an option too, if you don't have to rely on a script being active only once at any given time. Forgotten to AdlibUnregister something and things can go nasty.

Share this post


Link to post
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
Sign in to follow this  
Followers 0