dv8 Posted March 10, 2006 Share Posted March 10, 2006 Is it possible the compiled script to restart itself when pressed a button or selected menuitem? Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
MHz Posted March 10, 2006 Share Posted March 10, 2006 Yes, explain further if you want help in some direction. Link to comment Share on other sites More sharing options...
kclteam Posted March 10, 2006 Share Posted March 10, 2006 yups...like Suicide.au3 (a self-deleting script) you could make a batch file when the button is clicked which closes the script and then starts it again... not sure if that will work, but just a suggestion I believe we should all pay our tax with a smile. I tried - but they wanted cash! Link to comment Share on other sites More sharing options...
dv8 Posted March 10, 2006 Author Share Posted March 10, 2006 Yes, explain further if you want help in some direction.I have a script with "Restart" menuitem. I need when "Restart" is pressed, the script to restart itself (exit and then start again). Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
tonedeaf Posted March 10, 2006 Share Posted March 10, 2006 I have a script with "Restart" menuitem. I need when "Restart" is pressed, the script to restart itself (exit and then start again).Would me more like: start executable and then exit.Treat the compiled executable just like another exe file. Link to comment Share on other sites More sharing options...
dv8 Posted March 10, 2006 Author Share Posted March 10, 2006 Would me more like: start executable and then exit. Treat the compiled executable just like another exe file. Not happen that way, because there can be only one instance of it. it has the line: If UBound(ProcessList(@ScriptName)) > 2 Then Exit That's because it has many HOTKEYS and if there is another instance the hotkeys mess up. Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
neogia Posted March 10, 2006 Share Posted March 10, 2006 Just create a script in the same directory that's something like this: ProcessClose($firstScriptName) Sleep(2000) Run(@ComSpec & FileGetShortName(@ScriptDir) & "\" & $firstScriptName) That should work just fine. [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia Link to comment Share on other sites More sharing options...
dv8 Posted March 10, 2006 Author Share Posted March 10, 2006 Just create a script in the same directory that's something like this: ProcessClose($firstScriptName) Sleep(2000) Run(@ComSpec & FileGetShortName(@ScriptDir) & "\" & $firstScriptName) That should work just fine. That's not an option. As you can see the topic title says: Self-Rstarting script Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 That's not an option. As you can see the topic title says: Self-Rstarting script Well, the idea that you have If UBound(ProcessList(@ScriptName)) > 2 Then ExitIs easily overcome, all the user has to do is rename the .exe ... so that's all you have to do too. I don't know if this is all correct... but I tested it once and it seemed to work:expandcollapse popup#include <GUIConstants.au3> #include <file.au3> Global $NULL = '', $fz_Name = '' Global $PathSplit = _PathSplit(@AutoItExe, $NULL, $NULL, $fz_Name, $NULL) If IsArray($PathSplit) Then If StringInStr($PathSplit[3], '___') Then Execute('Opt("OnExitFunc", "_SelfDelete")') EndIf Opt('MouseCoordMode', 2) $Main = GUICreate("Example", 140, 60,-1, -1) $Button1 = GUICtrlCreateButton("Restart", 20, 10, 100, 40) GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then Exit If $msg = $Button1 Then If IsArray($PathSplit) Then If Not StringInStr($PathSplit[3], '___') Then NewExe() ElseIf StringInStr($PathSplit[3], '___') Then MsgBox(0, 'Error', 'Error, you must exit completely then manually restart') EndIf EndIf EndIf WEnd Func NewExe() FileCopy(@ScriptFullPath, @ScriptDir & '\' & StringTrimRight(@ScriptName, 4) & '____.exe') Sleep(1000) If FileExists(@ScriptDir & '\' & StringTrimRight(@ScriptName, 4) & '____.exe') Then Run(@ScriptDir & '\' & StringTrimRight(@ScriptName, 4) & '____.exe') Exit EndFunc Func _SelfDelete() If IsArray($PathSplit) Then If StringInStr($PathSplit[3], '___') Then Local $sCmdFile = '' FileDelete(@TempDir & "\scratch.bat") $sCmdFile = 'ping -n ' & '127.0.0.1 > nul' & @CRLF _ & ':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'del ' & @TempDir & '\scratch.bat' FileWrite(@TempDir & "\scratch.bat", $sCmdFile) Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE) EndIf EndIf EndFuncThere's no error checking, so you would have to do that yourself... But I did make sure that it didn't delete the original copy, only the one that you are making to restart. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
kclteam Posted March 10, 2006 Share Posted March 10, 2006 (edited) That way I guess the idea about creating a temp batch file to do the dirty job would be useful.Only trouble is I have no idea how to use batch files...search the forum for a Suicide.au3 and try deciphering that. That is a self-deleting script...you can always modify it to suit ur needs. Edit: Yay...SmOke_N's method works on my box too... Edited March 10, 2006 by kclteam I believe we should all pay our tax with a smile. I tried - but they wanted cash! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 That way I guess the idea about creating a temp batch file to do the dirty job would be useful.Only trouble is I have no idea how to use batch files...search the forum for a Suicide.au3 and try deciphering that. That is a self-deleting script...you can always modify it to suit ur needs. Edit: Yay...SmOke_N's method works on my box too...If you type SelfDelete (Then Space Bar) in SciTe, it will automatically insert in your script . Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
kclteam Posted March 10, 2006 Share Posted March 10, 2006 Mine doesnot enter any function...though it makes the term SelfDelete red in color... SciTe version is 1.67...do I need to upgrade or something? I believe we should all pay our tax with a smile. I tried - but they wanted cash! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 Mine doesnot enter any function...though it makes the term SelfDelete red in color...SciTe version is 1.67...do I need to upgrade or something?Press the space bar right after you type it. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MHz Posted March 10, 2006 Share Posted March 10, 2006 (edited) Mine doesnot enter any function...though it makes the term SelfDelete red in color... SciTe version is 1.67...do I need to upgrade or something?Tou may need to update your definitions as sometimes may not setup the abbreviations correctly on a new install. It can be done through Scite Config or the Start Menu. @dv8 How about this for restarting. ; Requires Beta If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf ;... ;... ;... While 1 Switch GUIGetMsg() Case $buttonGO Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit ;... ;... ;... Edited March 10, 2006 by MHz Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 Tou may need to update your definitions as sometimes may not setup the abbreviations correctly on a new install. It can be done through Scite Config or the Start Menu. @dv8 How about this for restarting. ; Requires Beta If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf ;... ;... ;... While 1 Switch GUIGetMsg() Case $buttonGO Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit ;... ;... ;...That's super nice MHz!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
dv8 Posted March 10, 2006 Author Share Posted March 10, 2006 I decided to compromise with: If UBound(ProcessList(@ScriptName)) > 2 Then Exit making it : If UBound(ProcessList(@ScriptName)) > 3 Then Exit And use this function to restart: Func _Restart() Run(@ScriptFullPath) exit EndFunc If anyone can come up with a way to self-restart script (by this i mean FIRST exit he script and THEN start it again) without any additional BAT files, please notify me Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 I decided to compromise with: If UBound(ProcessList(@ScriptName)) > 2 Then Exit making it : If UBound(ProcessList(@ScriptName)) > 3 Then Exit And use this function to restart: Func _Restart() Run(@ScriptFullPath) exit EndFunc If anyone can come up with a way to self-restart script (by this i mean FIRST exit he script and THEN start it again) without any additional BAT files, please notify me MHz... has the perfect example... but you sure are picky!!... here's a working exampleIf Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf $Main = GUICreate("Example", 140, 60,-1, -1) $Button1 = GUICtrlCreateButton("Restart", 20, 10, 100, 40) GUISetState() While 1 $msg = GUIGetMsg() If $msg = - 3 Then Exit If $msg = $Button1 Then Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit EndIf WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
dv8 Posted March 10, 2006 Author Share Posted March 10, 2006 Tou may need to update your definitions as sometimes may not setup the abbreviations correctly on a new install. It can be done through Scite Config or the Start Menu. @dv8 How about this for restarting. ; Requires Beta If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> '/restart' Then Exit EndIf ;... ;... ;... While 1 Switch GUIGetMsg() Case $buttonGO Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /restart') Exit ;... ;... ;... I thought of this, but this way, when the script is started with "/restart" it won't have the UBOUND... line and it won't prevent starting another instance of the script... Free Remote Desktop Software For Windows Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 10, 2006 Moderators Share Posted March 10, 2006 (edited) I thought of this, but this way, when the script is started with "/restart" it won't have the UBOUND... line and it won't prevent starting another instance of the script... Errr, yes it does... Just compile my example and see for yourself. Edit: I should have said, look at the ElseIf Statement... I'm tired off to bed [Yawn] [/Yawn] Edited March 10, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MHz Posted March 10, 2006 Share Posted March 10, 2006 (edited) MHz... has the perfect example... but you sure are picky!!... here's a working exampleThanks. I suppose one could use just Run(@ScriptFullPath) in the example without using Beta, but prevents Au3 execution as when UnCompiled. @dv8 It is If conditional on whether a 2nd instance starts or not. Using the switch restart will allow a 2nd instance and close the first. You cannot have it both ways of executing a 2nd instance and not allowing it. Edit: If you want, have a look at FAQ 14 and apply it within the restart part of the If block. Edited March 10, 2006 by MHz 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