Sign in to follow this  
Followers 0
Metaborn

Process that will only run if it's not already running

3 posts in this topic

I'm trying to create a program that will set in the background and monitor stuff. I don't want more then one copy of the program to run, so I've created a function that lists all process's with it's name, and kills all the process's except the one with the lowest PID. In unix that would work for keeping the original process running, but I just found out in windows that this does not work. I'm trying to avoid using a locking method.

Does anyone have any ideas. If there was a way to get the current process ID, then I could work with that.

Func CheckIfAlreadyRunning()
    Local $list
    Local $FirstProcessID = 99999999999999999
    
    $list = ProcessList("IPC_Monitor.exe")
    for $i = 1 to $list[0][0]
        ConsoleWrite($list[$i][0] & "   " & $list[$i][1] & @CR)
        If($list[$i][1] < $FirstProcessID) Then 
            $FirstProcessID = $list[$i][1]
        EndIf
    next

    for $i = 1 to $list[0][0]
        If $list[$i][1] <> $FirstProcessID Then
            ProcessClose($list[$i][1])
        EndIf
    next
    
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Take a look at _Singleton() in the helpfile. It should provide the functionally you are looking for.

Edited by SolidSnake

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites

Take a look at _Singleton() in the helpfile. It should provide the functionally you are looking for.

Wow, cool thx. Works like a charm

It's always nice when you don't have to reinvent the wheel

Share this post


Link to post
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
Sign in to follow this  
Followers 0