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?
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?