locked
How to config a program can only be runned once? RRS feed

  • Question

  • Hi,

    In our company we have a problem. We have a program installed on every pc that our users need.

    Now when the program runs, it should be configed when they click the desktop icon again that the program doesn't excuted again. Because when it is excuted twice, they get errors and every day we get such calls.

    The question is, is there any solution when the program is running, they can't run it again?

    Thanks in advance.

    Friday, November 26, 2010 9:55 AM

Answers

  • here you go

    tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I /N "notepad.exe">NUL

    IF %ERRORLEVEL% == 0 GOTO popup
    IF %ERRORLEVEL% == 1 GOTO EXEC

    :popup
    START CMD /C "ECHO Application Already Running, Press any key to close this window&& PAUSE"
    exit

    :EXEC
    start notepad.exe

    :EXIT
    exit


    MCSE | MCITP - Server 2008 | MCITP - Exchange 2007 | MCTS - Exchange 2010
    • Marked as answer by StijnS Monday, November 29, 2010 2:31 PM
    Monday, November 29, 2010 2:19 PM

All replies

  • you could run a domain wide script to prevent multiple instances of the programs process from running.WMI can help you with that.


    Tunde Abagun MCP,MCSA,MCTS,MCITP en p "for the love of Computers"
    Sunday, November 28, 2010 2:12 AM
  • Is it really not possible?

    Cuss I have programs installed when you click on it and that program is already running, I get a pop up message: Program is already running.

    Monday, November 29, 2010 8:28 AM
  • See if this helps (create a batch file with the following)

    tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I /N "notepad.exe">NUL
    if "%ERRORLEVEL%"=="0" exit
    if "%ERRORLEVEL%"=="1" notepad.exe goto exit

    its very basic but achives what you are looking for. Replace notepad.exe with your application name.

     


    MCSE | MCITP - Server 2008 | MCITP - Exchange 2007 | MCTS - Exchange 2010
    • Proposed as answer by HereToHelp Monday, November 29, 2010 1:02 PM
    Monday, November 29, 2010 11:14 AM
  • It works for notepad.exe but when I put my program in the script, nothing happens :(
    Monday, November 29, 2010 11:28 AM
  • are you trying correct imagename and path for your app?

    go to taskman while you application is running, see the imagename and with the correct path for your app try to run the batch file while it is open and closed. post the result.

    I am positive that there is a way to achieve what you are looking for.


    MCSE | MCITP - Server 2008 | MCITP - Exchange 2007 | MCTS - Exchange 2010

    Monday, November 29, 2010 11:48 AM
  • Ok it is working.

    How can I change the icon? Cus now I have an icon af a bat file.

    Monday, November 29, 2010 12:54 PM
  • instead of using the actual batch file, let users use a shortcut to the batch file and you will be able to give the shortcut any icon you want.

    glad you got it working. below is a cleaner batch file (just in case you like it better)

    tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I /N "notepad.exe">NUL

    IF %ERRORLEVEL% == 0 GOTO EXIT
    IF %ERRORLEVEL% == 1 GOTO EXEC

    :EXEC
    start notepad.exe

    :EXIT
    exit


    MCSE | MCITP - Server 2008 | MCITP - Exchange 2007 | MCTS - Exchange 2010
    Monday, November 29, 2010 1:04 PM
  • Ok thanks again.

    Now one more question. Is there a possibility when the application is running and they click the icon again they get a popup message, with some text in?

    Monday, November 29, 2010 1:33 PM
  • here you go

    tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I /N "notepad.exe">NUL

    IF %ERRORLEVEL% == 0 GOTO popup
    IF %ERRORLEVEL% == 1 GOTO EXEC

    :popup
    START CMD /C "ECHO Application Already Running, Press any key to close this window&& PAUSE"
    exit

    :EXEC
    start notepad.exe

    :EXIT
    exit


    MCSE | MCITP - Server 2008 | MCITP - Exchange 2007 | MCTS - Exchange 2010
    • Marked as answer by StijnS Monday, November 29, 2010 2:31 PM
    Monday, November 29, 2010 2:19 PM
  • Thanks, I also found a VBS script:

     

    Set WshShell = WScript.CreateObject ("WScript.Shell")

    Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process")

    vFound = False

    For Each objProcess in colProcessList

                    If objProcess.name = "notepad.exe" then

                                    vFound = True

                    End if

    Next

    If vFound = False then

                    WshShell.Run("notepad.exe")

    Else

                    MsgBox("Application already running")

    End if

    Monday, November 29, 2010 2:31 PM