G
Guest
i trying to collect windows services. i'm getting inconsistencies.
the collection works every time locally. but remote collection yields
different result depending on my lab environment.
1) in the same domain i start the collection on the remote machine
i can get some 19 services without a problem then it will fail with:
'wmiService.ClassPath' threw an exception of type
'System.InvalidCastException'
System.Management.ManagementPath {System.InvalidCastException}
here is more data:…
System.Management.ManagementException was unhandled
Message="Not found "
Source="System.Management"
StackTrace:
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode)
at System.Management.ManagementObject.Get()
yet it was successful some 19 times before.
2) when i try this over 2 domain and pass the options with all the logon
rights it will fail on the first collection.
i found an MSDN code sample that is what i want to do.
1) i get call "ServiceController"
2)i call a "Win32_Service"
i don't understand why the exception. i don't know how
to get away from it. when it dies it dies at
"wimService.Get()"
public string[] getXprServices(bool oRunning)
{
string strmachine = "MYREMOTEMACHINE";
ConnectionOptions options = new ConnectionOptions();
ServiceController[] xprServices;
xprServices = ServiceController.GetServices(strmachine);
string[,] aServices = new string[xprServices.Length + 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 (ServiceController sServices in xprServices)
{
aServices[iElement, 0] = sServices.ServiceName;
aServices[iElement, 1] = sServices.DisplayName;
aServices[iElement, 2] = sServices.Status.ToString();
ManagementScope scope = new ManagementScope("\\\\" + strmachine
+ "\\root\\cimv2");
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" +
sServices.ServiceName + "'");
wmiService.Get();
aServices[iElement, 3] = wmiService["StartName"].ToString();
aServices[iElement, 4] =
sServices.ServicesDependedOn.Length.ToString();
}
iElement++;
}//foreach(ServiceController sServices in xprServices)
return (saServices);
}
the collection works every time locally. but remote collection yields
different result depending on my lab environment.
1) in the same domain i start the collection on the remote machine
i can get some 19 services without a problem then it will fail with:
'wmiService.ClassPath' threw an exception of type
'System.InvalidCastException'
System.Management.ManagementPath {System.InvalidCastException}
here is more data:…
System.Management.ManagementException was unhandled
Message="Not found "
Source="System.Management"
StackTrace:
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus
errorCode)
at System.Management.ManagementObject.Get()
yet it was successful some 19 times before.
2) when i try this over 2 domain and pass the options with all the logon
rights it will fail on the first collection.
i found an MSDN code sample that is what i want to do.
1) i get call "ServiceController"
2)i call a "Win32_Service"
i don't understand why the exception. i don't know how
to get away from it. when it dies it dies at
"wimService.Get()"
public string[] getXprServices(bool oRunning)
{
string strmachine = "MYREMOTEMACHINE";
ConnectionOptions options = new ConnectionOptions();
ServiceController[] xprServices;
xprServices = ServiceController.GetServices(strmachine);
string[,] aServices = new string[xprServices.Length + 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 (ServiceController sServices in xprServices)
{
aServices[iElement, 0] = sServices.ServiceName;
aServices[iElement, 1] = sServices.DisplayName;
aServices[iElement, 2] = sServices.Status.ToString();
ManagementScope scope = new ManagementScope("\\\\" + strmachine
+ "\\root\\cimv2");
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" +
sServices.ServiceName + "'");
wmiService.Get();
aServices[iElement, 3] = wmiService["StartName"].ToString();
aServices[iElement, 4] =
sServices.ServicesDependedOn.Length.ToString();
}
iElement++;
}//foreach(ServiceController sServices in xprServices)
return (saServices);
}