using System.Management;private string Test(string sInfoName,string sColName)
{
int itemCount = 0;
if(sInfoName=="")return "";
object myValue = ""; // Instantiate an object searcher with this query
try
{
// Build a query for enumeration of Win32_BaseBoard instances
SelectQuery query = new SelectQuery(sInfoName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection myCollection = searcher.Get();
myCollection = searcher.Get();
foreach(ManagementObject myMgmtObj in myCollection)
{
PropertyData Property = myMgmtObj.Properties[sColName];
myValue = Property.Value;
}
}
catch{}
return Convert.ToString(myValue);
}调用上面的方法,执行下面一句:
string s = Test("Win32_Processor","ProcessorId");
s就是CPU的ID号。不过,这个id号,在很多pc上是看不到的。
{
int itemCount = 0;
if(sInfoName=="")return "";
object myValue = ""; // Instantiate an object searcher with this query
try
{
// Build a query for enumeration of Win32_BaseBoard instances
SelectQuery query = new SelectQuery(sInfoName);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection myCollection = searcher.Get();
myCollection = searcher.Get();
foreach(ManagementObject myMgmtObj in myCollection)
{
PropertyData Property = myMgmtObj.Properties[sColName];
myValue = Property.Value;
}
}
catch{}
return Convert.ToString(myValue);
}调用上面的方法,执行下面一句:
string s = Test("Win32_Processor","ProcessorId");
s就是CPU的ID号。不过,这个id号,在很多pc上是看不到的。
解决方案 »
- [讨论]有没有办法写一个小程序堵塞局域网络?
- 如何取得静态函数的调用函数
- 如何用asp.net实现设为首页和加入收藏夹
- VS2010 SQL Server 2008 Database Project里为何没有Data Generation Plans
- Socket断线后自动重连,大家帮帮忙,谢谢了
- 如何做好数据库调优
- ftp服务器怎么配制??IIS或ftp serv-u??
- 活动目录的问题!!!微软专家来看!
- 简单问题,轻松拿分!一个关于线程终止的问题?
- 请各位高手帮帮忙,怎样使用模式对话框?
- dataGrid能不能直接用OleDbDataReader作数据源?
- 在C#中有两个编写代码的地方,一个为HTML,一个是C#,他们之间要怎么样进行数据传递
Dim encryptMachineCode As String = String.Empty
Dim searcher As New ManagementObjectSearcher("SELECT MACAddress FROM Win32_NetworkAdapter")
Dim share As ManagementObject 'Get macaddress
For Each share In searcher.Get()
If share("MACAddress") <> String.Empty Then
machineCodeString = share("MACAddress")
machineCodeString = machineCodeString.Replace(":", String.Empty)
machineCodeString = machineCodeString.Trim()
Exit For
End If
Next 'get cpu id
If machineCodeString = String.Empty Then
searcher = New ManagementObjectSearcher("Select ProcessorId From Win32_Processor")
For Each share In searcher.Get()
If share("ProcessorId") <> String.Empty Then
machineCodeString = share("ProcessorId")
machineCodeString = machineCodeString.Trim()
Exit For
End If
Next
End If 'get main board id
If machineCodeString = String.Empty Then
searcher = New ManagementObjectSearcher("Select SerialNumber From Win32_BIOS")
For Each share In searcher.Get()
If share("SerialNumber") <> String.Empty Then
machineCodeString = share("SerialNumber")
machineCodeString = machineCodeString.Trim()
Exit For
End If
Next
End If