Jump to content

How to self check if running


dirty
 Share

Recommended Posts

Can you guys help me ? i cant figure out how to have script to check if its running, and if it is then just exit it but keep previous instance unaffected.

I tried

$proc = processexist ("test.exe")
if $proc > "" Then
Exit

This will exit its self as soon as i lauch it, but somehow i need to make it to maybe set status as "running" and then check for that status somehow ?

Just cant think of anything.

Thanks in advance.......

Edited by dirty
Link to comment
Share on other sites

It sounds like you want _Singleton(), see helpfile.

Edit: Before I forget, you should change that avatar. You're basically saying you want to crush Jos and I don't think he would like that.

Edited by AdmiralAlkex
Link to comment
Share on other sites

Here's another option. It works with an open file.

Since it can't delete an open file, it will exit.

;#NoTrayIcon
; [-------------- Check Instance --------------]
If FileExists(@TempDir & "\temp.tmp") Then FileDelete(@TempDir & "\temp.tmp")
Sleep(500) ; <-- Might need to adjust value
If FileExists(@TempDir & "\temp.tmp") Then Exit
$OnlyOneInstanceAllowed = FileOpen(@TempDir & "\temp.tmp", 1)

It's an old trick -- but it works.

Of course, you would need to rename "temp.tmp" to something special

for your particular script.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

AdmiralAlkex, I should ban you for reporting this thread. I've lost 20 points of intelligence just reading it.

Yeah maybe I should have sent it from the user profile. Sorry :D
Link to comment
Share on other sites

thanks guys.

If test.exe isn't running then the script would continue ?

No it wont run at all.... because once its executed it is considered as running process so EXIT.

I am also not after delighting or renaming files, so that wont work.

Thanks to admiral alkex for _Singleton(), thats all i needed to know :D

In the end

$filename = FileExists (@ScriptDir & "\GR4 loader.exe")
If $filename = 0 Then
    MsgBox(16,"Error","GR4 loader.exe was renamed. Please Rename back to GR4 loader.exe")
    Exit
    EndIf
if _Singleton("GR4 loader.exe",1) = 0 Then
    Msgbox(0,"Information.","Only one instance is allowed.")
    Exit
EndIf

Works just fine :huggles:

And come on guys my avatar is funny as hell.... but ill delete it if JOS wont like it. Hopefully ill get a warning before BAN for having avatars modified.

Plus his avatar does not say who it is, i just saw a picture and had a funny idea, crashing someone's name was not the plan.

Edited by dirty
Link to comment
Share on other sites

And come on guys my avatar is funny as hell.... but ill delete it if JOS wont like it. Hopefully ill get a warning before BAN for having avatars modified.

Plus his avatar does not say who it is, i just saw a picture and had a funny idea, crashing someone's name was not the plan.

You did get a warning. Also, I don't recall giving you a reason, I simply told you to change it. I don't necessarily agree with AdmiralAlkex's reason why you should change it but I do agree that you should change it. Now change your avatar before I do ban you since you have acknowledged you know it needs change.
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...