By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,833 Members | 2,067 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,833 IT Pros & Developers. It's quick & easy.

Trying To Query Remote Machine Using WMI & ASP.NET Fails With "Invalid Class"

P: n/a
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\testconfiguration s.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
}

Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.