Morteza Posted October 5, 2008 Share Posted October 5, 2008 Dears,I Searched the forum & help file already, but no answer was found.I want if my script is running previously, when the user executed another copy of my script, the previous executed copy be closed and new copy be ran. I know, I can close the previous copy by ProcessClose() function, but what if the user changed my script name? How can I recognize what is the new script name to close it by ProcessClose()? Can I define an internal name for my script for recognizing it if the name was changed by user?Best Link to comment Share on other sites More sharing options...
ProgAndy Posted October 5, 2008 Share Posted October 5, 2008 I suppose to create a GUID and set it as AutItWinSetTitle Then, before you set it, check if there are other Wins with this title and make WinClose Global Const $AutoItTitle = "MyAPP:6598834c-6cc7-45ea-9cd3-89dd825a2977" ; change the GUID to a Unique one for this app: e.g. use http://www.guidgen.com/ __UniqueThis() ; Prog@ndy Func __UniqueThis() While WinExists($AutoItTitle) WinKill($AutoItTitle) WEnd AutoItWinSetTitle($AutoItTitle) EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Morteza Posted October 5, 2008 Author Share Posted October 5, 2008 I suppose to create a GUID and set it as AutItWinSetTitle Then, before you set it, check if there are other Wins with this title and make WinClose Global Const $AutoItTitle = "MyAPP:6598834c-6cc7-45ea-9cd3-89dd825a2977" ; change the GUID to a Unique one for this app: e.g. use http://www.guidgen.com/ __UniqueThis() ; Prog@ndy Func __UniqueThis() While WinExists($AutoItTitle) WinKill($AutoItTitle) WEnd AutoItWinSetTitle($AutoItTitle) EndFunc Thanks for your very quick answer My script work at background; without any window. Can I use your tip at this situation? Regards Link to comment Share on other sites More sharing options...
Skrip Posted October 5, 2008 Share Posted October 5, 2008 Yes you can. Just make a window, hide it (@SW_HIDE) and then have your script exit when the window is closed. [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
Morteza Posted October 6, 2008 Author Share Posted October 6, 2008 Yes you can. Just make a window, hide it (@SW_HIDE) and then have your script exit when the window is closed.Thank you very much. I will test it :-) Link to comment Share on other sites More sharing options...
ProgAndy Posted October 6, 2008 Share Posted October 6, 2008 No you don't need to create one. Each AutoIt App (not shure about those compiled as CUI) has an invisible window you can Access with AutoItWinSetTitle / AutoItWinGetTitle And those windows are recognized by WinExists *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
SoulA Posted October 6, 2008 Share Posted October 6, 2008 Can't you put something like this in the beginning of your script so to prevent the user from running a script with a different name? If @ScriptName <> "name you want here" Then Exit Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 6, 2008 Share Posted October 6, 2008 That is valid code. You can verify the script name but you might want to give some kind of message saying it's been changing. Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 6, 2008 Share Posted October 6, 2008 That is valid code. You can verify the script name but you might want to give some kind of message saying it's been changing. Link to comment Share on other sites More sharing options...
Morteza Posted October 7, 2008 Author Share Posted October 7, 2008 No you don't need to create one. Each AutoIt App (not shure about those compiled as CUI) has an invisible window you can Access with AutoItWinSetTitle / AutoItWinGetTitle And those windows are recognized by WinExists That worked great Thanks again Link to comment Share on other sites More sharing options...
Morteza Posted October 7, 2008 Author Share Posted October 7, 2008 Can't you put something like this in the beginning of your script so to prevent the user from running a script with a different name? If @ScriptName <> "name you want here" Then Exit Thanks for your reply, No! the codes such as your code just will work on current script, not previous running script. I want replace current script with previous running script. ProgAndy tip worked excellent. 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