C # obtain WINDOWS system information,
The System. Management namespace must be referenced,
The Code is as follows:
1 public class SysProp 2 {3 public SysProp () 4 {5 6 ManagementObjectSearcher PhysicalMemory = new ManagementObjectSearcher ("select * from Win32_PhysicalMemory "); 7. Export Processor = new ManagementObjectSearcher ("select * from Win32_Processor"); 8. ManagementObjectSearcher OS = new ManagementObjectSearcher ("select * from Win32_OperatingSystem"); 9. Ntroller = new ManagementObjectSearcher ("select * from Win32_VideoController"); 10 ManagementObjectSearcher CompSys = new bytes ("select * from Win32_ComputerSystem"); 11 12 bytes = String. format ("{0} MB", Convert. toInt64 (GetValue (PhysicalMemory, "Capacity")/1024/1024); 13 14 ProcessorName = (string) GetValue (Processor, "Name"); 15 16 OperatingSystemBit = System. Environment. Is64BitOperatingSystem? "64-bit": "32-bit"; 17 OS _Caption = (string) GetValue (OS, "Caption"); 18 OS _Version = System. environment. OSVersion. version. toString (); 19 ServicePack =! String. IsNullOrEmpty (System. Environment. OSVersion. ServicePack) 20? System. environment. OSVersion. servicePack21: "NONE"; 22 SystemSpecialFolder = System. environment. getFolderPath (System. environment. specialFolder. system); 23 Video_Caption = (string) GetValue (VideoController, "Caption"); 24 UserName = System. environment. userName; 25 UserDomainName = System. environment. userDomainName; 26 CompSys_Workgroup = (string) GetValue (CompSys, "Workgroup"); 27} 28 29 private object GetValue (ManagementObjectSearcher searcher, string propName) 30 {31 foreach (ManagementObject mobj in searcher. get () 32 return mobj [propName]; 33 throw new NotSupportedException (); 34} 35 36 // <summary> 37 // physical memory 38 // </summary> 39 public string PhysicalMemory_Capacity {get; set ;} 40 41 // <summary> 42 // processor 43 /// </summary> 44 public string ProcessorName {get; set ;} 45 46 /// <summary> 47 // processor architecture 48 /// </summary> 49 public string OperatingSystemBit {get; set ;} 50 51 // <summary> 52 // window name 53 /// </summary> 54 public string OS _Caption {get; set ;} 55 56 /// <summary> 57 // window version 58 /// </summary> 59 public string OS _Version {get; set ;} 60 61 // <summary> 62 // 63 // </summary> 64 public string ServicePack {get; set ;} 65 66 // <summary> 67 // system directory 68 /// </summary> 69 public string SystemSpecialFolder {get; set ;} 70 71 // <summary> 72 // graphics card name 73 /// </summary> 74 public string Video_Caption {get; set ;} 75 76 // <summary> 77 // UserName 78 /// </summary> 79 public string UserName {get; set ;} 80 81 // <summary> 82 // computer name 83 /// </summary> 84 public string UserDomainName {get; set ;} 85 86 // <summary> 87 // workgroup 88 // </summary> 89 public string CompSys_Workgroup {get; set;} 90}
View Code