//取CPU号
public string GetCpuID()
{
try
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strCpuID = null ;
foreach( ManagementObject mo in moc )
{
strCpuID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strCpuID;
}
catch
{
return "";
}
}
//取第一块硬盘号
public string GetHardDiskID()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
string strHardDiskID = null ;
foreach(ManagementObject mo in searcher.Get())
{
strHardDiskID = mo["ModuleNumber"].ToString().Trim();
if(strHardDiskID != "")
{
break;
}
}
return strHardDiskID ;
}
catch
{
return "";
}
}//end
//取第一块网卡号
public string GetNetworkID()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
string strNetworkID = null ;
foreach(ManagementObject mo in searcher.Get())
{
strNetworkID = mo["MACAddress"].ToString().Trim();
if(strNetworkID != "")
{
break;
}
}
return strNetworkID ;
}
catch
{
return "";
}
}//end
//取串口
public int getport(int portnum)
{
//链接服务器
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
//检测是否已存在相同串口的站点,并获取PORT值
foreach(DirectoryEntry e in root.Children)
{
if(e.SchemaClassName == "IIsWebServer")
{
if(e.Properties["ServerBindings"].Value != null)
{
int strstart = e.Properties["ServerBindings"].Value.ToString().IndexOf(":",0);
int strend = e.Properties["ServerBindings"].Value.ToString().IndexOf(":",strstart+1);
string thisport = e.Properties["ServerBindings"].Value.ToString().Substring((strstart+1),(strend-strstart-1));
if(thisport == portnum.ToString())
{
portnum++;
portnum = getport(portnum);
break;
}
}
}
}
return portnum;
}
posted on 2006-05-30 08:46
CqRandy 阅读(559)
评论(0) 编辑 收藏 引用 所属分类:
C#