Get the Type of the OS(Windows)

Get the operating system info by using the classes from namespace System.Management. OS: Windows XP, Vista, Win7, Windows Server 2008 and so _disibledevent=> 1 using System; 2 using System.Management; 3 4 namespace GetOSInfo_Peter 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 SelectQuery query = new SelectQuery("Win32_operatingSystem"); 11 ManagementObjectSearcher searcher = new ManagementObjectSearcher(query); 12 ManagementObjectCollection objs = searcher.Get(); 13 14 foreach (ManagementObject obj in objs) 15 { 16 Console.WriteLine(obj.GetPropertyValue("Caption").ToString()); 17 Console.WriteLine(obj.GetPropertyValue("BootDevice").ToString()); 18 Console.WriteLine(obj.GetPropertyValue("BuildNumber").ToString()); 19 Console.WriteLine(obj.GetPropertyValue("CSDVersion").ToString()); 20 Console.WriteLine(obj.GetPropertyValue("Manufacturer").ToString()); 21 Console.WriteLine(obj.GetPropertyValue("Version").ToString()); 22 Console.WriteLine(obj.GetPropertyValue("SystemDirectory").ToString()); 23 break; 24 } 25 } 26 } 27 }
Output:
Get the Type of the OS(Windows)
Output all the info by "Console.WriteLine(obj.GetText(TextFormat.Mof))".
The os info can be found in "wbemtest". Type "wbemtest" in 'Run', then connect to "root\cimv2" namespace, "Enum Classes..." -> select "Recursive" _disibledevent=>System.Management

[MSDN]Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure.Applications and services can query for interesting management information (such as how much free space is left _disibledevent=>The classes that are used in the above source code:
SelectQuery Represents a WQL SELECT data query.
ManagementObjectSearcher Retrieves a collection of management objects based _disibledevent=>ManagementObjectCollection Represents different collections of management objects retrieved through WMI.
ManagementObject Represents a WMI instance.
Tags: 

延伸阅读

最新评论

发表评论