how to get hdd info within asp.net app?

G

Guest

i have class

using System;
using System.Management;
using System.Collections;

public class CmpHDDUtility
{
public CmpHDDUtility()
{
}

class HardDrive
{
private string model = null;
private string type = null;
private string serialNo = null;

public string Model
{
get { return model; }
set { model = value; }
}

public string Type
{
get { return type; }
set { type = value; }
}

public string SerialNo
{
get { return serialNo; }
set { serialNo = value; }
}
}

public void CmpHdd(string modl, string tp, string ser)
{
ArrayList hdCollection = new ArrayList();

ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT *
FROM Win32_DiskDrive");

foreach (ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
try
{
hd.Model = wmi_HD["Model"].ToString();
hd.Type = wmi_HD["InterfaceType"].ToString();
hdCollection.Add(hd);
}
catch
{ }
}


int i = 0;
foreach (ManagementObject wmi_HD in searcher.Get())
{
// get the hard drive from collection
// using index
HardDrive hd = (HardDrive)hdCollection;

// get the hardware serial no.
if (wmi_HD["SerialNumber"] == null)
hd.SerialNo = "None";
else
hd.SerialNo = wmi_HD["SerialNumber"].ToString();

++i;
}


HardDrive hdd = (HardDrive)hdCollection[0];
if ((hdd.Model != modl) || (hdd.Type != tp) || (hdd.SerialNo != ser))
throw new NotSupportedException();

}
}

and it's work well in console application? but in asp.net app
it breaks on

hd.Model = wmi_HD["Model"].ToString();

statement with "Object reference not set to an instance of an object." error

how can I resolve this problem?
 
M

Mark Fitzpatrick

It could very well be a permissions issue. For one thing, the docs say that
the queries will not work for partially trusted code. The System.Web
namespace is, by definition, partially trusted code so it could be that
running this through an ASP.Net app, which is partially trusted, is your
problem. I'm not sure what is the best way to make a fully trusted ASP.Net
app, but at least this should give you an idea where to start looking.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 

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,525
Members
44,997
Latest member
mileyka

Latest Threads

Top