C# VS2003 : Windows Services Get the PId

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Gray
    New Member
    • Apr 2008
    • 47

    C# VS2003 : Windows Services Get the PId

    Hello,

    I am trying to force a service to close if it is hanging in 'Stopping' status and wanted to use:

    Code:
    pId = System.Diagnostics.Process.GetProcessesByName(ServiceName)[0].Id;
    This does not work, says index is outside the range, which means there is nothing in the list for it to evaluate. I suspect this will not work with services but only applications.

    Can someone please direct me to a way of accessing the processes Pid so i can carry out the tasks i require.

    Many thanks.
Working...