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!
[code=cpp]
using System;
using System.Diagnost ics;
using System.Manageme nt;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
public class WMITest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l mdLabel;
protected System.Web.UI.W ebControls.Labe l cnLabel;
protected System.Web.UI.W ebControls.Labe l memLabel;
protected System.Web.UI.W ebControls.Labe l errorLabel;
public string Usr = "";
public void Page_Load(objec t sender, EventArgs e)
{
GetWmiData();
}
public void GetWmiData()
{
try
{
ConnectionOptio ns co = new ConnectionOptio ns();
co.Username = "user";
co.Password = "password";
co.Authority = "ntdlmdomain:do main";
ManagementScope ms = new ManagementScope ("\\\\ip_addres s\\root\\cimv2" , co);
ms.Connect();
ObjectQuery query = new ObjectQuery("SE LECT * FROM Win32_ComputerS ystem");
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(ms,qu ery);
ManagementObjec tCollection queryCollection = searcher.Get(); foreach (ManagementObje ct queryObj in queryCollection )
{
cnLabel.Text = queryObj["Name"].ToString();
mdLabel.Text = queryObj["Model"].ToString();
memLabel.Text = queryObj["TotalPhysicalM emory"].ToString();
catch (ManagementExce ption ex)
{
errorLabel.Text = ex.Message.ToSt ring();
}
}
}[/code]
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!
[code=cpp]
using System;
using System.Diagnost ics;
using System.Manageme nt;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
public class WMITest : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Labe l mdLabel;
protected System.Web.UI.W ebControls.Labe l cnLabel;
protected System.Web.UI.W ebControls.Labe l memLabel;
protected System.Web.UI.W ebControls.Labe l errorLabel;
public string Usr = "";
public void Page_Load(objec t sender, EventArgs e)
{
GetWmiData();
}
public void GetWmiData()
{
try
{
ConnectionOptio ns co = new ConnectionOptio ns();
co.Username = "user";
co.Password = "password";
co.Authority = "ntdlmdomain:do main";
ManagementScope ms = new ManagementScope ("\\\\ip_addres s\\root\\cimv2" , co);
ms.Connect();
ObjectQuery query = new ObjectQuery("SE LECT * FROM Win32_ComputerS ystem");
ManagementObjec tSearcher searcher = new ManagementObjec tSearcher(ms,qu ery);
ManagementObjec tCollection queryCollection = searcher.Get(); foreach (ManagementObje ct queryObj in queryCollection )
{
cnLabel.Text = queryObj["Name"].ToString();
mdLabel.Text = queryObj["Model"].ToString();
memLabel.Text = queryObj["TotalPhysicalM emory"].ToString();
catch (ManagementExce ption ex)
{
errorLabel.Text = ex.Message.ToSt ring();
}
}
}[/code]
Comment