Jump to content

Check Process


Recommended Posts

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

Maybe show us your code?

Link to comment
Share on other sites

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

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. :whistle:

Link to comment
Share on other sites

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

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

Give 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

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. :whistle:

Well your right there..... I'll see if there's another fix, or if SpookMeister's is aplicible, use then it instead.

Link to comment
Share on other sites

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

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

Edited by Generator
Link to comment
Share on other sites

Link to comment
Share on other sites

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

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

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

Thanks a lot as you guide me through with these explainations, and now I learned something lol :whistle: , 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...