The release number of this article has been CHS304283
For Microsoft Visual Basic .NET versions of this article, see
CHS304289.
For Microsoft Visual C .NET versions of this article, see
CHS307394.
This task content
summary
Require WINDOWS version data acquisition operating system information determination platform to determine how Windows 95, Windows 98, Windows 98 Second Edition or Windows Me determines how Windows NT, Windows 2000 or Windows XP specific version generation example
SUMMARY This article gradually describes how to determine which operating system is used on the system where the application is located. This article will illustrate the differences between Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows 98 Second Edition, Microsoft Windows Millennium Edition (Windows Me), Microsoft Windows NT 3.51, Microsoft Windows NT 4.0, Microsoft Windows 2000 and Microsoft XP.
Back to top
Claim
Microsoft Visual C # .NET has a medium-level Visual C # programming knowledge
Back to top
Get a Windows version data To determine the operating system running on the system, you must get the following data:
----------------------------------- -------------
| | Windows | Windows | Windows | Windows NT | Windows | Windows |
| | 95 | 98 | ME | 4.0 | 2000 | XP |
----------------------------------- -------------
| PlatformID | 1 | 1 | 1 | 2 | 2 | 2 |
----------------------------------- -------------
Major | | | | | | |
| Version | 4 | 4 | 4 | 4 | 5 | 5 |
----------------------------------- -------------
| Minor | | | | | | |
| Version | 0 | 10 | 90 | 0 | 0 |
----------------------------------- -------------
Note: In order to use all 32-bit version of Windows, the code in this article has been verified, though, but Windows 95 and Windows NT 3.51 do not support Microsoft Visual Studio .NET or public language runtime.
Back to top
Get operating system information
The System name space contains a name called
OperatingSystem's class.
The properties of the OperatingSystem class provide the necessary information about the operating system being used. System.environment class
Osversion property returns
OperatingSystem object.
System.OperatingSystem Osinfo = System.environment.OSVERSION;
Back to top
Determine the platform
The first step in the OPERATINGSYSTEM information is to determine which platform is being used. can use
Operatingsystem
The PlatformID property is determined which platform is used.
E.g,
The enumeration value of the Win32Windows property indicates one of the following operating systems:
WINDOWS 95 Windows 98 Windows 98 Second Edition Windows ME,
Winnt properties indicate one of the following operating systems:
Windows NT 3.51 Windows NT 4.0 Windows 2000 Windows XP
Switch (Osinfo.platform)
{
Case System.PlatformID.WIN32WINDOWS:
{
// Code to Determine Specific Version Of Windows 95,
// Windows 98, Windows 98 SECOND Edition, or Windows ME.
}
Case system.platformid.win32nd:
{
// Code to Determine Specific Version Of Windows NT 3.51,
// Windows NT 4.0, Windows 2000, or Windows XP.
}
}
Back to top
Determine the specific version of Windows 95, Windows 98, Windows 98 Second Edition, or Windows Me, if the platform is Windows 95, Windows 98, Windows 98 Second Edition or Windows Me, you can analyze the main version Remote version to determine the specific version.
// Platform Is Windows 95, Windows 98, Windows 98 SECOND EDITION,
// or windows me.
Case System.PlatformID.WIN32WINDOWS:
Switch (osinfo.version.minor)
{
Case 0:
Console.Writeline ("Windows 95");
Break;
Case 10:
IF (osinfo.version.revision.tostring () == "2222a")
Console.writeline ("Windows 98 Second Edition);
Else
Console.writeline ("Windows 98");
Break;
Case 90:
Console.WriteLine ("Windows Me");
Break;
} Break;
Back to top
Determine the specific version of Windows NT, Windows 2000 or Windows XP If you determine that the platform is Windows NT 3.51, Windows NT 4.0, Windows 2000 or Windows XP, the specific version can be determined by analyzing the main version or subsequence.
// Platform Is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// or windows XP.
Case system.platformid.win32nd:
Switch (osinfo.version.major)
{
Case 3:
Console.writeline ("Windows NT 3.51");
Break;
Case 4:
Console.writeLine ("Windows NT 4.0");
Break;
Case 5:
IF (Osinfo.version.minor == 0)
Console.writeline ("Windows 2000");
Else
Console.writeLine ("Windows XP");
Break;
} Break;
Back to top
Generate an example below to generate a test scheme that demonstrates this feature:
In Visual Studio .NET, open a new C # console application. The code window of the class1.cs will open by default. Replace all code in the class1.cs code editor window as the following sample code: use system;
Namespace determineos_cs
{
Class class1
{
Static void main (string [] args)
{
// Get Operatingsystem Information from the system namespace.
System.OperatingSystem Osinfo = System.environment.OSVERSION;
// determine the platage.
Switch (Osinfo.platform)
{
// Platform Is Windows 95, Windows 98,
// Windows 98 Second Edition, or Windows ME.
Case System.PlatformID.WIN32WINDOWS:
Switch (osinfo.version.minor)
{
Case 0:
Console.Writeline ("Windows 95");
Break;
Case 10:
IF (osinfo.version.revision.tostring () == "2222a")
Console.writeline ("Windows 98 Second Edition);
Else
Console.writeline ("Windows 98");
Break;
Case 90:
Console.WriteLine ("Windows Me");
Break;
}
Break;
// Platform Is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// or windows XP.
Case system.platformid.win32nd:
Switch (osinfo.version.major)
{
Case 3:
Console.writeline ("Windows NT 3.51");
Break;
Case 4:
Console.writeLine ("Windows NT 4.0");
Break;
Case 5:
IF (Osinfo.version.minor == 0)
Console.writeline ("Windows 2000");
Else
Console.writeLine ("Windows XP");
Break;
} Break;
}
Console.readline ();
}
}
} Press CTRL F5 combination keys to run the application. Please note that the Windows version will appear in the console window.
Back to top
The information in this article applies to:
Microsoft Visual C # .NET (2002) Recent Updated: 2002-7-29 (1.0) Keyword KBDsupport Kbhowto KbhowTomaster Kbprod2Web KB304283