Jump to content

Recommended Posts

Posted

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

Posted

I suppose to create a GUID and set it as AutItWinSetTitle :P 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

Posted

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 :idea:

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 :P

My script work at background; without any window. Can I use your tip at this situation?

Regards

Posted

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]

Posted

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 :-)

Posted

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 :P 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

Posted

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 :P And those windows are recognized by WinExists :(

That worked great :) Thanks again :idea:

Posted

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.

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
×
×
  • Create New...