1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
public static string GetOsServicePack() {
return GetWMIInfo("Win32_OperatingSystem", "CSDVersion");
}
private static string GetWMIInfo(string sSegment, string sInfo) {
string sSearchFile = "";
ManagementClass cimobject = new ManagementClass(sSegment);
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc) {
foreach(PropertyData s in mo.Properties) {
try {
if(s.Name.Equals(sInfo)) {
sSearchFile = mo[s.Name].ToString();
}
}
catch(System.NullReferenceException) {
continue;
}
}
}
return sSearchFile.Trim();
}
|