2

We have a program that sits on a server and should always be running, but it is important that only one instance of it should be running. We added a registry key in 'HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run' so that it would run on startup.

However, we are getting a problem when multiple users log into the server over remote desktop - an instance is starting for each user. How can we get it so that it starts only once, no matter how many users are logged in?

4
  • 2
    Use a batch (cmd) file that checks to see if it is already running. If it running then exit otherwise start the program.
    – DavidPostill
    Aug 27, 2015 at 9:45
  • 1
    As @DavidPostill says, use a script. Change your run registry to point to your script that checks. Ideally, however, you shouldn't be messing with the registry... Windows has a useful set of tools called Scheduled Tasks than can be set to run when a/any user logs in...
    – Kinnectus
    Aug 27, 2015 at 9:49
  • Add the program as a service - then assign 1 logon user and put the startup type as automatic
    – Jay
    Aug 27, 2015 at 9:50
  • Thanks everyone for your input - you helped me get to a decent solution (please see answer for details) Aug 27, 2015 at 10:27

1 Answer 1

0

Thanks to @DavidPostill for guiding me in the right direction.

I made a batch file as suggested, using the following question on stackoverflow as a basis: https://stackoverflow.com/questions/162291/how-to-check-if-a-process-is-running-via-a-batch-script

Here's what I came up with:

SETLOCAL EnableExtensions
set EXE=MyProgram.exe
FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND
start C:/path/to/MyProgram.exe
:FOUND

I then changed the registry entry to point at this batch file rather than the executable itself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .