C#.net, Monitor process on remote machine and start if it's not running

Man of Honour
Joined
18 Oct 2002
Posts
13,262
Location
Northallerton/Harrogate
Hello,

What's the besterest/easiest way to do that thing wot I wrote in that title?

I would like to monitor whether or not a process is running on a remote machine when my bit o' software starts up, and if not, start it.

I'm trying to get my walnut-sized brain around WMI but I appear to have lost all cognitive ability today.

My main h'application is written in C# (VS 2010). If that helps.

Thanks for any advice.
 
Code:
        static bool CheckIfRunning(string processName)
        {
            foreach (var p in Process.GetProcesses())
            {
                if (p.ProcessName.Contains(processName))
                    return true;
            }
            return false;
        }

Then use it like:

Code:
if(!CheckIfRunning("YourApplication"))
    Process.Start("PathToYourApplication.exe");
 
Last edited:
That would only work if the code was running on the same machine as the .exe - OP specifically wants to control this remotely.

What user does the .exe have to be running for? What does it do? If you need that level of control over it, it would be better to be written as a client/server and have the "thing" you want running on demand as a service.

If you don't control the .exe, you could always install a service which itself does the check in the code above. Then, if you make sure this new service is running, the service will make sure the .exe is running.

Convoluted, yes. Will it work? Probably.

:)
 
Hi Mr^B.

I don't know if we can install a service on the remote machine. The remote machine is a module that connects to our machine and has a bunch of stuff on it, and our manufacturing people are stupid and can't handle changes in software installation procedures very well.

The .exe always runs under Administrator. It is the main application that runs and controls the module hardware.
 
Back
Top Bottom