Services help

  • Thread starter Thread starter Bob Lazarchik
  • Start date Start date
B

Bob Lazarchik

Hello:

We manufacture tools used in the Semiconductor industry that have a DB
engine running on each one. I need to scan through the computers on the
company domain and find which ones have this service installed and it's
current state ( paused, running, stopped, etc ). Can anyone point me to a
set of classes in C# that allow me to find running services on computers
within a Domain?

Thanks for your help

Bob Lazarchik
SDI.
 
Bob

Check out the System.ServiceProcess.ServiceController type.

ServiceController iisService = new ServiceController();

try
{
iisService.MachineName = "MyServer";
iisService.ServiceName = "IISADMIN";

if ( iisService.Status == ServiceControllerStatus.Stopped )
{
Console.WriteLine( "Eek! Get help the websites down" );
}
}
catch ( System.InvalidOperationException )
{
Console.WriteLine( "OOPS! The machine doesn't have the service
installed" );
}

HTH

Glenn
 
Bob/Scott

Very useful article, here's the C# version....

ConnectionOptions co = new ConnectionOptions();
co.Username = "userName";
co.Password = "password";

ManagementScope scope = new ManagementScope( @"\\myServer\root\cimv2", co );
ObjectQuery query = new ObjectQuery( "select * from win32_service" );
ManagementObjectSearcher mos = new ManagementObjectSearcher( scope, query );
ManagementObjectCollection moc = mos.Get();

foreach ( ManagementObject mo in moc )
{
Console.WriteLine( "{0} : {1}", mo["Name"].ToString(),
mo["State"].ToString() );
}

Check this link out for more info on Win32_Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
win32_service.asp

HTH

Glenn
 
Very cool, Glenn.

--
Scott

Bob/Scott

Very useful article, here's the C# version....

ConnectionOptions co = new ConnectionOptions();
co.Username = "userName";
co.Password = "password";

ManagementScope scope = new ManagementScope( @"\\myServer\root\cimv2", co );
ObjectQuery query = new ObjectQuery( "select * from win32_service" );
ManagementObjectSearcher mos = new ManagementObjectSearcher( scope, query );
ManagementObjectCollection moc = mos.Get();

foreach ( ManagementObject mo in moc )
{
Console.WriteLine( "{0} : {1}", mo["Name"].ToString(),
mo["State"].ToString() );
}

Check this link out for more info on Win32_Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/
win32_service.asp
 
Back
Top