Sven Posted August 5, 2011 Share Posted August 5, 2011 (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 August 6, 2011 by Sven Link to comment Share on other sites More sharing options...
somdcomputerguy Posted August 5, 2011 Share Posted August 5, 2011 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. Link to comment Share on other sites More sharing options...
Sven Posted August 5, 2011 Author Share Posted August 5, 2011 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now