473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Remote WMI Connections C# ASP.Net

20
Hello,
I've been trying to get a remote connection to WMI working in a C# ASPX page. I know I'm doing something wrong, but I've seen too many variations of how to do it to make heads or tails out of anything. I'm new .NET so I'm sure I'm not doing it right. My code is below and it generates an "Invalid Parameter" Exception. Can someone show me how to make the remote connection by supplying credentials and school me by fixing any of my rookie mistakes? I'm compiling the .CS file into a DLL if that makes any difference. Thanks so much!

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Diagnostics;
  3. using System.Management;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10.  
  11. public class WMITest : System.Web.UI.Page
  12. protected System.Web.UI.WebControls.Label mdLabel;
  13. protected System.Web.UI.WebControls.Label cnLabel; 
  14. protected System.Web.UI.WebControls.Label memLabel; 
  15.  
  16. protected System.Web.UI.WebControls.Label errorLabel; 
  17. public string Usr = "";
  18.  
  19. public void Page_Load(object sender, EventArgs e) 
  20. {
  21.     GetWmiData();
  22.  
  23. public void GetWmiData() 
  24.     try
  25.     {
  26.         ConnectionOptions co = new ConnectionOptions(); 
  27.         co.Username = "user";
  28.         co.Password = "password"; 
  29.         co.Authority = "ntdlmdomain:domain";
  30.         ManagementScope ms = new ManagementScope("\\\\ip_address\\root\\cimv2", co); 
  31.         ms.Connect();
  32.         ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
  33.        ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms,query);
  34.        ManagementObjectCollection queryCollection = searcher.Get();foreach (ManagementObject queryObj in queryCollection) 
  35.         { 
  36.             cnLabel.Text = queryObj["Name"].ToString();
  37.             mdLabel.Text = queryObj["Model"].ToString(); 
  38.             memLabel.Text = queryObj["TotalPhysicalMemory"].ToString();
  39.     catch (ManagementException ex) 
  40.     {
  41.         errorLabel.Text = ex.Message.ToString();
  42.     }
  43.  }
  44. }
Aug 23 '07 #1
1 3354
stilmas
20
I think I got it. I changed around a few things just stabbing in the dark and it works:
Expand|Select|Wrap|Line Numbers
  1. public void Page_Load(object sender, EventArgs e)
  2. {
  3.     GetWmiData();
  4. }
  5.  
  6. public void GetWmiData()
  7. {
  8.     ConnectionOptions co = new ConnectionOptions();
  9.     co.EnablePrivileges = true;
  10.     co.Impersonation = ImpersonationLevel.Impersonate;
  11.     co.Username = "user";
  12.     co.Password = "password";
  13.  
  14.     ManagementScope ms = new ManagementScope("\\\\IP_ADDR\\root\\cimv2", co);
  15.  
  16.     try
  17.     {
  18.         ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_ComputerSystem");
  19.         ManagementObjectSearcher searcher = new ManagementObjectSearcher(ms,query);
  20.         ManagementObjectCollection queryCollection = searcher.Get();
  21.  
  22.         foreach (ManagementObject queryObj in queryCollection)
  23.         {
  24.             cnLabel.Text = queryObj["Name"].ToString();
  25.             mdLabel.Text = queryObj["Model"].ToString();
  26.             memLabel.Text = queryObj["TotalPhysicalMemory"].ToString();
  27.         }
  28.  
Aug 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bennett Haselton | last post by:
In Visual Studio .Net 2002 Server Explorer, if I add a new connection under "Data Connections", I can specify a remote server name and the username and password that I want to use, but then when...
5
by: felecha | last post by:
I have a VB.Net application that runs as a Windows Service and monitors a MessageQueue on another machine. At times that machine will have to be rebooted, so I've been working on how to get my...
3
by: Hrvoje Vrbanc | last post by:
Hello all! Scenario: - web server at one location (domain) with VS 2003 - SQL server at a remote location (domain) - VPN connection on port 1433 between the two domains I have no troubles...
6
by: 3Dfelix | last post by:
Hi, someone could help me with this problem when trying to insert a record in a SQL express database? I can view record but not edit or insert. When connecting to SQL Server 2005, this failure...
10
by: cleo | last post by:
I am migrating from VB6/Access to Visual Basic and SQL Express. I have success writing test code on my local machine and am now setting up tests for deployment to a server. I have installed SQL...
2
by: CLM | last post by:
When I test the remote access at work (lapttop computer to desk top computer) the connection works fine. When I bring the laptop home and try to connect to my desktop I get the error msg: The...
8
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is...
0
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ...
5
by: Cirene | last post by:
I just deployed my new ASP.NET (3.5 FW) site to the hosting company I'm using, webhost4life. NOTE: I HAVE deployed other SQL Server sites to the same account with no issues. Now I'm getting...
7
by: RN1 | last post by:
Is it possible to connect to my local SQL Server 2005 database from a remote web server? If yes, what ConnectionString do I use? Thanks, Ron
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.