none
Detect if SB program is being used RRS feed

  • Question

  • Is there a way to detect if my small basic program is running?

    I would like for only one instance of the program to run at a time, is this possible?

    Friday, May 11, 2012 5:52 PM

Answers

  • I use my own extension for this, but try Data extension Process.ExistByName("yourSBprogram").  Note no .exe extension.

    EDIT

    Thinking about this, the above will always be true because the current running code will be true and it gives no indication of how many instances there are running.

    My extension does return a list of all processes running in an array and perhaps that would be required.  I don't see this option on the Data extension or the Fremy one, but I could be wrong.

    EDIT2

    Actually, my extension also cannot handle this since the returned array is indexed by the process name, not the ID (which is unique and would be much better as an index) - I will change this!

    FINAL EDIT!

    Updated and uploaded my extension (LitDev.dll) since this was clearly an oversight not indexing by unique ID.  If you are interested, this then works, where my exe is called process.exe.

    processes = LDProcess.GetProcesses()
    processID = Array.GetAllIndices(processes)
    count = 0
    For i = 1 To Array.GetItemCount(processID)
      If (processes[processID[i]] = "process") Then
        count = count + 1
        TextWindow.WriteLine(processID[i])
      EndIf
    EndFor
    TextWindow.WriteLine(count)
    Friday, May 11, 2012 6:33 PM
    Moderator

All replies

  • There are extensions that list running processes and you could query these to check if another instance of your program is running. 

    Or you could just create a small file in a fixed location with the current time in it and delete the file when the program ends. If your program updates the time in the file periodically (perhaps a timer event every minute) then if for some reason the program crashed and the file was not deleted you could check the current time in the file and if it was more than 1 minute ago, then assume the program is dead.


    Friday, May 11, 2012 5:59 PM
    Moderator
  • Hi Litdev,

    Yes, I did create a program that does as you suggested and it works ok, I was just not sure if it was the best way to go.

    I do use data extensions and Fremy extensions, do you know if either of those contain an object to detect running process? if so the name?

    Friday, May 11, 2012 6:09 PM
  • I use my own extension for this, but try Data extension Process.ExistByName("yourSBprogram").  Note no .exe extension.

    EDIT

    Thinking about this, the above will always be true because the current running code will be true and it gives no indication of how many instances there are running.

    My extension does return a list of all processes running in an array and perhaps that would be required.  I don't see this option on the Data extension or the Fremy one, but I could be wrong.

    EDIT2

    Actually, my extension also cannot handle this since the returned array is indexed by the process name, not the ID (which is unique and would be much better as an index) - I will change this!

    FINAL EDIT!

    Updated and uploaded my extension (LitDev.dll) since this was clearly an oversight not indexing by unique ID.  If you are interested, this then works, where my exe is called process.exe.

    processes = LDProcess.GetProcesses()
    processID = Array.GetAllIndices(processes)
    count = 0
    For i = 1 To Array.GetItemCount(processID)
      If (processes[processID[i]] = "process") Then
        count = count + 1
        TextWindow.WriteLine(processID[i])
      EndIf
    EndFor
    TextWindow.WriteLine(count)
    Friday, May 11, 2012 6:33 PM
    Moderator
  • Thank you for your help litdev,


    • Edited by SFC-P33A Monday, May 14, 2012 6:28 PM
    Monday, May 14, 2012 5:43 PM
  • litdev,

    Is there a way to find a specific processID? Suppose I had two or more instances of my program running with the same name ("IPS.exe") in different locations, each makes it's own set of text files. However, I do not want two of the same program at the same location running.

    Wednesday, May 16, 2012 8:48 PM
  • The code listed in earlier reply lists all process IDs with the same exe.
    Saturday, May 19, 2012 6:06 PM
    Moderator