Retrieving information about the Operating System
The 'OperatingSystem' class in System namespace can be used to retrieve various information about the operating system in which the .NET code is running.
The 'Environment' class in System namespace has a property called 'OSVersion' which returns an object of type OperatingSystem.
The OperatingSystem class has two important properties :
1. Platform - returns a PlatformId which represents the operating system platform. The PlatformId is an enum, which has the following values : . Win32NT ( indicates the current OS is Windows NT, 2000 or XP ) . Win32Windows ( indicates the current OS is Windows95, 98 or ME ) . Win32S . WinCE
2. Version - represents a Version object that describes the major version, minor version, build and revision of current operating system. The major version and minor version attributes can be used to determine which specific flavor of operating system is installed.
System.OperatingSystem osInfo = System.Environment.OSVersion;
string operatingSystem = "Unknown";
switch ( osInfo.Platform ) { case System.PlatformID.Win32Windows: // Current OS is Windows - can be Windows95, 98 or ME switch ( osInfo.Version.Minor ) { case 0: operatingSystem = "Windows 95"; break; case 10: operatingSystem = "Windows 98"; break; case 90: operatingSystem = "Windows Me"; break; } break;
case System.PlatformID.Win32NT: // Current OS is Windows NT, 2000 or XP switch ( osInfo.Version.Major ) { case 3: operatingSystem = "Windows NT 3.51"; break; case 4: operatingSystem = "Windows NT 4.0"; break; case 5: if ( osInfo.Version.Minor == 0 ) operatingSystem = "Windows 2000"; else operatingSystem = "Windows XP";
break; } break;
}
The following Microsoft Knowledge Base Articles provide more information and source code in VB.NET, C# and C++.
Ref :
1. http://support.microsoft.com/default.aspx?scid=kb;EN-US;304283 2. http://support.microsoft.com/default.aspx?scid=kb;EN-US;304289 3. http://support.microsoft.com/default.aspx?scid=kb;EN-US;307394
|
| Author: ezhil murugan 17 Jun 2004 | Member Level: Bronze Points : 0 |
came to know thro this article that .Net has an incredibly huge no. of classes doing various fascinating tasks
|