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上是看不到的。

解决方案 »

  1.   

    哦,错了,这个取到的是server的信息。你最好做一个dll,让客户端下载,然后使用这个方法。
      

  2.   

    Try            Dim machineCodeString As String = String.Empty
                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