yes Willy it is.
it is just that using System.Manageme nt does not collect all the field of WMI.
i was just hoping to use FrameWork over WMI.
i do have another problem. i figured how to get to the remote machine and
start the data collection but it runs then stops when reading the "DNS"
service and the error in VS C# 2005 does not tell me what the problem is. it
is very generic message stating "Get general help for this exception" when i
do a ManagementObjec t.wm.Get();
public string[] getXprServices( bool oRunning)
{
///once all the service is collected return the full array to
display to monitor.
///the way to get the detail i want requires that i call both
the framework
///and the wmi.
//for debug only!!
string strmachine = "server2";
ConnectionOptio ns options = new ConnectionOptio ns();
options.Usernam e = "usera";
options.Passwor d = "downriver" ;
options.Authori ty = "ntdlmdomain:my domain";
ServiceControll er[] xprServices;
xprServices = ServiceControll er.GetServices( strmachine);
string[,] aServices = new string[xprServices.Len gth + 1, 5];
int iElement = 1; //the service number incrementor
aServices[0, 0] = "Service Name";
aServices[0, 1] = "Display Name";
aServices[0, 2] = "Status";
aServices[0, 3] = "Log on As";
aServices[0, 4] = "# of Dependencies";
foreach (ServiceControl ler sServices in xprServices)
{
if (oRunning) //only collect the running services
{
if (sServices.Stat us == ServiceControll erStatus.Runnin g)
{
aServices[iElement, 0] = sServices.Servi ceName;
aServices[iElement, 1] = sServices.Displ ayName;
aServices[iElement, 2] = sServices.Statu s.ToString();
ManagementObjec t wmiService;
wmiService = new
ManagementObjec t("Win32_Servic e.Name='" + sServices.Servi ceName + "'");
wmiService.Get( );
aServices[iElement, 3] =
wmiService["StartName"].ToString();
aServices[iElement, 4] =
sServices.Servi cesDependedOn.L ength.ToString( );
}
}
else //all services
{
aServices[iElement, 0] = sServices.Servi ceName;
aServices[iElement, 1] = sServices.Displ ayName;
aServices[iElement, 2] = sServices.Statu s.ToString();
ManagementScope scope = new ManagementScope ("\\\\" +
strmachine + "\\root\\cimv2" , options);
//scope.Connect() ;
ManagementObjec t wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='"
+ sServices.Servi ceName + "'");
wmiService.Get( ); <<<< dies here!!!
aServices[iElement, 3] =
wmiService["StartName"].ToString();
//aServices[iElement, 3] = "";
aServices[iElement, 4] =
sServices.Servi cesDependedOn.L ength.ToString( );
}
iElement++;
}//foreach(Service Controller sServices in xprServices)
formatoutput fout = new formatoutput();
string[] saServices = fout.multiArray Format(aService s);
return (saServices);
}//public string[] getXprServices( )
"Willy Denoyette [MVP]" wrote:
"auldh" <au***@discussi ons.microsoft.c omwrote in message
news:FE******** *************** ***********@mic rosoft.com...
is there no way via framework to see the "startname" property of the service?
do i still have to call the "WMI"?
System.Manageme nt is part of the framework isn't it?
if so do i have to use:
System.Manageme nt.ManagementSc ope < to the remote machine\\root\\ cimv2
System.Manageme ntObject wmiService;
wmiService = new ManagementObjec t("Win32_Servic e.Name='" +
sServices.Servi ceName + "'");
in order to get the "startname" ?
i'm trying to get the details from both local and remote machines services.
You can get all properties you are interested in by using a WQL query like so:
string serviceName = "Spooler";
SelectQuery query = new SelectQuery("se lect StartName, Status from Win32_Service where
Name ='" + serviceName + "'");
using(Managemen tObjectSearcher searcher = new ManagementObjec tSearcher(query ))
{
foreach (ManagementObje ct mo in searcher.Get()) {
Console.WriteLi ne("{0} - {1} ", mo["StartName"], mo["Status"]);
}
}
Sure, to connect to a remote system, you'll need to specify a ManagementScope and
appropriate ConnectionOptio ns. Also, you need to take care of when connecting to a remote
machine is that you specify a user account with appropriate rights to query the WMI
namespace.
Willy.