hi all, how can i determine the OS at runtime. i tried thru system.environment.osversion but it shows the same result for both Win2k Professional and Win2k Server. How can I find whether the machine contains Win2k prof or Win2k server at runtime? Thanx in adv
Jay
Shaa, there are probably easier ways to do this, but here's one way using WMI, which enables you to query all sorts of stuff about the system. Here's some sample code:
string servername = "myserver";
ManagementScope oMs = new ManagementScope( "\\\\" + servername + "\\root\\cimv2" );
ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher( oMs, oQuery );
ManagementObjectCollection oReturnCollection = oSearcher.Get();
//loop through the result set (we really only expect one)
foreach ( ManagementObject mo in oReturnCollection )
{
string osname = (string) mo["Caption"];
string osver = (string) mo["Version"];
string owner = (string) mo["RegisteredUser"];
string sp = (string) mo["ServicePackMajorVersion"].ToString();
}
shaa
Member
85 Points
17 Posts
Determine whether win2k server or win2k professional
Sep 23, 2003 09:24 AM|LINK
Avi_P
Member
100 Points
20 Posts
Re: Determine whether win2k server or win2k professional
Sep 23, 2003 09:54 PM|LINK
string servername = "myserver"; ManagementScope oMs = new ManagementScope( "\\\\" + servername + "\\root\\cimv2" ); ObjectQuery oQuery = new ObjectQuery("SELECT * FROM Win32_OperatingSystem"); //Execute the query ManagementObjectSearcher oSearcher = new ManagementObjectSearcher( oMs, oQuery ); ManagementObjectCollection oReturnCollection = oSearcher.Get(); //loop through the result set (we really only expect one) foreach ( ManagementObject mo in oReturnCollection ) { string osname = (string) mo["Caption"]; string osver = (string) mo["Version"]; string owner = (string) mo["RegisteredUser"]; string sp = (string) mo["ServicePackMajorVersion"].ToString(); }For more information on other things you can query with WMI, check this link out: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_providers.asp And for more specific OS related queries, try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_classes.asp Tell me if that helps.Avi, VS.NET Build Team, Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights