会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Duke's Blog
博客园
首页
新随笔
联系
订阅
管理
C# 获取机器码Code
Code
1
using
System;
2
using
System.Management;
3
using
System.IO;
4
using
System.Runtime.InteropServices;
5
using
System.Security.Cryptography;
6
using
System.Text;
7
using
Microsoft.Win32;
8
9
namespace
CHUmanager.Common
10
{
11
/**/
///
<summary>
12
///
register 的摘要说明。
13
///
注册软件所用到的类
16
///
</summary>
17
public
class
Register
18
{
19
20
获取cpu序列号 硬盘ID 网卡硬地址
#region
获取cpu序列号 硬盘ID 网卡硬地址
21
/**/
///
<summary>
22
///
获取cpu序列号
23
///
</summary>
24
///
<returns>
string
</returns>
25
public
string
GetCpuInfo()
26
{
27
string
cpuInfo
=
""
;
28
ManagementClass cimobject
=
new
ManagementClass(
"
Win32_Processor
"
);
29
ManagementObjectCollection moc
=
cimobject.GetInstances();
30
foreach
(ManagementObject mo
in
moc)
31
{
32
cpuInfo
=
mo.Properties[
"
ProcessorId
"
].Value.ToString();
33
}
34
return
cpuInfo.ToString();
35
}
36
37
/**/
///
<summary>
38
///
获取硬盘ID
39
///
</summary>
40
///
<returns>
string
</returns>
41
public
string
GetHDid()
42
{
43
string
HDid
=
""
;
44
ManagementClass cimobject1
=
new
ManagementClass(
"
Win32_DiskDrive
"
);
45
ManagementObjectCollection moc1
=
cimobject1.GetInstances();
46
foreach
(ManagementObject mo
in
moc1)
47
{
48
HDid
=
(
string
)mo.Properties[
"
Model
"
].Value;
49
}
50
return
HDid.ToString();
51
}
52
53
/**/
///
<summary>
54
///
获取网卡硬件地址
55
///
</summary>
56
///
<returns>
string
</returns>
57
public
string
GetMoAddress()
58
{
59
string
MoAddress
=
""
;
60
ManagementClass mc
=
new
ManagementClass(
"
Win32_NetworkAdapterConfiguration
"
);
61
ManagementObjectCollection moc2
=
mc.GetInstances();
62
foreach
(ManagementObject mo
in
moc2)
63
{
64
if
((
bool
)mo[
"
IPEnabled
"
]
==
true
)
65
MoAddress
=
mo[
"
MacAddress
"
].ToString();
66
mo.Dispose();
67
}
68
return
MoAddress.ToString();
69
}
70
#endregion
71
}
72
}
posted @
2008-04-06 23:35
DukeCheng
阅读(
857
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告