- 积分
- 6146
- 在线时间
- 4481 小时
- 主题
- 281
- 注册时间
- 2013-6-7
- 帖子
- 1176
- 最后登录
- 2025-1-26
管理员
- 帖子
- 1176
- 软币
- 22811
- 在线时间
- 4481 小时
- 注册时间
- 2013-6-7
|
using System.Management;
//取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 "";
- }
- }
复制代码 //取第一块网卡号- 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 "";
- }
- }
复制代码 //取串口- 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;
- }
复制代码 |
评分
-
查看全部评分
|