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

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
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top