473,587 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Remote WMI Connections C# ASP.Net

20 New Member
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 3372
stilmas
20 New Member
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
1537
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 the database appears, if I right-click on "Tables", there's no option to add a new table. If I right-click "Servers" in Server Explorer instead and...
5
5739
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 Service to re-establish the connection after the remote machine is back. I found that as soon as the remote machine goes down, the BeginReceive()...
3
2565
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 reaching the remote SQL server either from SQL Enterprise manager or in VS 2003 design-time (using the SQL authentication in both cases) - all the...
6
20900
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 may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 -...
10
5775
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 Express on a Windows 2003 Server. I can connect and create databases on the Remote Server from my local machine using SQL Management Express, so I...
2
2465
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 client could not connect to the remote computer. Remote connections might not be enabled or the computer might be too busy to accept new connections. It...
8
2826
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 put into stand-by or hibernation 3. later, computer is brought out of stand-by or hibernation 4. when trying to save or close form, SQL exception...
0
1991
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 ((string)(this.GetPropertyValue("Address1")));
5
3539
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 this error. Any idea why? Server Error in '/myuser4/MyWebApp' Application....
7
5928
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
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.