1

Possible Duplicate:
C# Process Monitor

I am trying to write a windows service that detects the Start up and Closing of processes on one of my servers. It seems I can get this information rather easy using Process object if I launch the application myself, but not other processes. It sounds like a very service to write, but have not made any progress.

Community
  • 1
  • 1
MikeZappa
  • 21
  • 2
  • You mean like this? http://stackoverflow.com/questions/7277620/getting-a-list-of-processes-in-asp-net – Ian Mercer Oct 24 '11 at 16:58
  • That's horribly expensive and inaccurate. Use http://stackoverflow.com/questions/1986249/c-sharp-process-monitor/1986856#1986856 – Hans Passant Oct 25 '11 at 02:05

2 Answers2

0

Your best bet is to use WMI. Make an RPC call to that remote server, authenticate properly, and do a query with WMI to retrieve Processes running.

apollosoftware.org
  • 12,161
  • 4
  • 48
  • 69
  • Getting the processes running, is not the problem, but detecting when they close is, that is where I am stuck, being unable to detect the process stopping. – MikeZappa Oct 24 '11 at 17:14
0

You can use the OpenProcess function to open a process handle for each process currently running. All you need is the process IDs. You can then use the process handles in whatever wait function you prefer; they become signaled when the corresponding process exits.

Detecting when a new process is launched is harder. If polling for new processes is not satisfactory, you'll need to write a device driver and use the PsSetCreateProcessNotifyRoutine function.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158