W
Winterminute
I am trying to read a list of install programs using WMI with ASP.NET/C#.
However, it fails with "Invalid Class".
I have confirmed that if I query LOCALHOST then it works fine, but if I
query a remote machine then it fails. If I enter incorrect credentials,
then it fails with an access denied, so I know that I am at least connecting
to the WMI provider.
Here is the error:
Invalid class
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Management.ManagementException: Invalid class
Source Error:
Line 503: foreach(ManagementObject oReturn in oReturnCollection )
Source File: c:\program files\asp.net starter kits\asp.net portal
(csvs)\portalcsvs\desktopmodules\testconfigurations.ascx.cs Line: 503
Here is what my code looks like:
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = AdminUserName;
oConn.Password = AdminPass;
System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + Servername + "\\root\\cimv2",
oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("Select * FROM Win32Reg_AddRemovePrograms");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach(ManagementObject oReturn in oReturnCollection )
{
// Do something, but I don't even get into the foreach, it dies trying
to access the first object
}
However, it fails with "Invalid Class".
I have confirmed that if I query LOCALHOST then it works fine, but if I
query a remote machine then it fails. If I enter incorrect credentials,
then it fails with an access denied, so I know that I am at least connecting
to the WMI provider.
Here is the error:
Invalid class
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Management.ManagementException: Invalid class
Source Error:
Line 503: foreach(ManagementObject oReturn in oReturnCollection )
Source File: c:\program files\asp.net starter kits\asp.net portal
(csvs)\portalcsvs\desktopmodules\testconfigurations.ascx.cs Line: 503
Here is what my code looks like:
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = AdminUserName;
oConn.Password = AdminPass;
System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + Servername + "\\root\\cimv2",
oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("Select * FROM Win32Reg_AddRemovePrograms");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();
foreach(ManagementObject oReturn in oReturnCollection )
{
// Do something, but I don't even get into the foreach, it dies trying
to access the first object
}