Generator Posted March 28, 2007 Share Posted March 28, 2007 Anyone give me a hint on how to prevent the program for running twice, like I clicked it twice but only wanted to run it once I tried PID check but wouldn't work Thanks for helping Generator Link to comment Share on other sites More sharing options...
BrettF Posted March 28, 2007 Share Posted March 28, 2007 Anyone give me a hint on how to prevent the program for running twice, like I clicked it twice but only wanted to run it onceI tried PID check but wouldn't workThanks for helpingGeneratorMaybe show us your code? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
SpookMeister Posted March 28, 2007 Share Posted March 28, 2007 From the Help File (Frequently Asked Questions) 14. How can I make sure only one copy of my script is run? The easiest way is to rename the title of the hidden AutoIt window when your script first starts. Then in the same script check for that window title existing - if it does then another copy of the script is running. ; Place at the top of your script $g_szVersion = "My Script 1.1" If WinExists($g_szVersion) Then Exit ; It's already running AutoItWinSetTitle($g_szVersion) ; Rest of your script goes here [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Generator Posted March 28, 2007 Author Share Posted March 28, 2007 For example: $Pid=@AutoitPID $PidCheck=ProcessExists($Pid) If $PidCheck=$Pid Then Exit EndIf While 1 ;My loop stuff here WEnd It wouldn't work because I don't know the right place to put it, also something about logic because once its doing the check the process is already running so I think it will just exits it. Link to comment Share on other sites More sharing options...
Generator Posted March 28, 2007 Author Share Posted March 28, 2007 From the Help File (Frequently Asked Questions)But my script does not have an active windows, or WinExists checks the process manager, I am really confused. Anyways my script name in process manager is same as 1 of the Windows process(Ex.svchost.exe)So won't that check just disable my process?Thanks for helping Link to comment Share on other sites More sharing options...
SpookMeister Posted March 28, 2007 Share Posted March 28, 2007 But my script does not have an active windows, or WinExists checks the process manager, I am really confused. Anyways my script name in process manager is same as 1 of the Windows process(Ex.svchost.exe)So won't that check just disable my process?Thanks for helpingGive it a shot.. I think you will find that it works just fine. [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
BrettF Posted March 28, 2007 Share Posted March 28, 2007 It wouldn't work because I don't know the right place to put it, also something about logic because once its doing the check the process is already running so I think it will just exits it. Well your right there..... I'll see if there's another fix, or if SpookMeister's is aplicible, use then it instead. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
Helge Posted March 28, 2007 Share Posted March 28, 2007 I guessed that we would see some interesting code when you said you tried to check PID. The script is using it's own PID and checks if it's running. There's quite some logic there. What about using _Singleton instead ? Link to comment Share on other sites More sharing options...
Generator Posted March 28, 2007 Author Share Posted March 28, 2007 (edited) Thanks for all the help, I guess SpookMeister's way worked.Anyways I am wondering, where can I find a list of those default variable like $g_szVersion or $iPID and stuff.I guessed that we would see some interesting code when you said you tried to check PID.The script is using it's own PID and checks if it's running. There's quite some logic there.What about using _Singleton instead ?Also can you explain to me how _Singleton works if you got time? Since I am noob at this.Thanks again Edited March 28, 2007 by Generator Link to comment Share on other sites More sharing options...
BrettF Posted March 28, 2007 Share Posted March 28, 2007 #include "Misc.au3" if _Singleton("test\test",1) = 0 Then Msgbox(0,"Warning","An occurence of test is already running") Exit EndIf Msgbox(0,"OK","the first occurence of test is running") Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
SpookMeister Posted March 28, 2007 Share Posted March 28, 2007 Thanks for all the help, I guess SpookMeister's way worked.Anyways I am wondering, where can I find a list of those default variable like $g_szVersion or $iPID and stuff.Also can you explain to me how _Singleton works if you got time? Since I am noob at this.Thanks again I can't help you very much with the PID thing, as I must admit that I don't have much knowledge in that area, but I think I can explain how the method I pointed you to works. Someone please correct me if I am wrong.Every time you are running an Autoit script, what you are really doing is running a program "Autoit" that is interpreting the instructions that your script has given it. This Autoit program is by default hidden in the background. What the instructions that I pointed you to do is stick a relatively unique title ("My Script 1.1") or whatever you put in between the quotes there, into a rather uniquely named variable "$g_szVersion". This could have just as easily been a variable called "$bob" but the former version follows a more logical naming convention.Next the instructions check to see it there is already an Autoit window (a hidden instance of the Autoit program) running with the specific title string that you gave it earlier. If that window exists, then it will close itself so that it doesn't do anyting to conflict with the already running version of the script. That is why these instructions are put at the top, before you do anything intrusive with your code.Next, it assigns the title string you gave it to its own hidden Autoit window. This is what you were checking for in the last step. Kind of seams like putting the cart before the horse at first, but when you think about it for a bit it starts to make more sense.Hope that helped.-SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
Generator Posted March 28, 2007 Author Share Posted March 28, 2007 I can't help you very much with the PID thing, as I must admit that I don't have much knowledge in that area, but I think I can explain how the method I pointed you to works. Someone please correct me if I am wrong.Every time you are running an Autoit script, what you are really doing is running a program "Autoit" that is interpreting the instructions that your script has given it. This Autoit program is by default hidden in the background. What the instructions that I pointed you to do is stick a relatively unique title ("My Script 1.1") or whatever you put in between the quotes there, into a rather uniquely named variable "$g_szVersion". This could have just as easily been a variable called "$bob" but the former version follows a more logical naming convention.Next the instructions check to see it there is already an Autoit window (a hidden instance of the Autoit program) running with the specific title string that you gave it earlier. If that window exists, then it will close itself so that it doesn't do anyting to conflict with the already running version of the script. That is why these instructions are put at the top, before you do anything intrusive with your code.Next, it assigns the title string you gave it to its own hidden Autoit window. This is what you were checking for in the last step. Kind of seams like putting the cart before the horse at first, but when you think about it for a bit it starts to make more sense.Hope that helped.-SpookMeisterThanks a lot as you guide me through with these explainations, and now I learned something lol , what you said about a hidden autoit window really helped me understood this whole thing as well as you gave me new ideas to work with, thanks again.Generator 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