using System;
using System.Management;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main( string[] args )
{
Console.WriteLine( GetServicePath( "AudioSrv" ) );
Console.ReadLine();
}
static string GetServicePath( string serviceName )
{
using( ManagementObjectSearcher mos = new
ManagementObjectSearcher( "SELECT PathName FROM Win32_Service WHERE Name =
\"" + serviceName + "\"" ) )
{
foreach( ManagementObject mo in mos.Get() )
{
return Path.GetDirectoryName( mo[
"PathName" ].ToString() );
}
}
throw new FileNotFoundException( "Service not found." );
}
}
}
Ragu said:
Hi All
I have to get the path of a Running Windows Service from another
application.
How to do this ?