C#マシンコードの取得

9197 ワード

 1  /// <summary>///  
2 /// </summary>
3 public class MachineCode
4 {
5 ///<summary>
6 /// cpu
7 ///</summary>
8 ///<returns> string </returns>
9 public string GetCpuInfo()
10 {
11 string cpuInfo = " ";
12 using (ManagementClass cimobject = new ManagementClass("Win32_Processor"))
13 {
14 ManagementObjectCollection moc = cimobject.GetInstances();
15
16 foreach (ManagementObject mo in moc)
17 {
18 cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
19 mo.Dispose();
20 }
21 }
22 return cpuInfo.ToString();
23 }
24
25 ///<summary>
26 /// ID
27 ///</summary>
28 ///<returns> string </returns>
29 public string GetHDid()
30 {
31 string HDid = " ";
32 using (ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive"))
33 {
34 ManagementObjectCollection moc1 = cimobject1.GetInstances();
35 foreach (ManagementObject mo in moc1)
36 {
37 HDid = (string)mo.Properties["Model"].Value;
38 mo.Dispose();
39 }
40 }
41 return HDid.ToString();
42 }
43
44 ///<summary>
45 ///
46 ///</summary>
47 ///<returns> string </returns>
48 public string GetMoAddress()
49 {
50 string MoAddress = " ";
51 using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
52 {
53 ManagementObjectCollection moc2 = mc.GetInstances();
54 foreach (ManagementObject mo in moc2)
55 {
56 if ((bool)mo["IPEnabled"] == true)
57 MoAddress = mo["MacAddress"].ToString();
58 mo.Dispose();
59 }
60 }
61 return MoAddress.ToString();
62 }
63 }