Jump to content

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


Recommended Posts

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
Link to comment
Share on other sites

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