How to Use Visual C #. Net to check the Windows version

Source: Internet
Author: User
Tags support microsoft

Obtain Windows Data
Obtain windows Information
Judgment Platform
Determine the version of Windows 95, Windows 98, Windows 98, or Windows ME
Determine the version of Windows NT, Windows 2000, or Windows XP
Compilation example

--------------------------------------------------------------------------------

Overview
This document describes how to check the operating system on which your application runs. This document distinguishes between Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows 98, Microsoft Windows 98, Microsoft Windows Millennium Edition (Windows ME), Microsoft Windows NT 3.51, Microsoft Windows NT 4.0, Microsoft Windows 2000, and Microsoft Windows XP.
Obtain Windows Data
To check the operating system, you must obtain the following data:

+ -------------------------------------------------------------- +
| Windows NT | Windows |
| 95 | 98 | Me | 4.0 | 2000 | XP |
+ -------------------------------------------------------------- +
| Platformid | 1 | 1 | 1 | 2 | 2 |
+ -------------------------------------------------------------- +
| Major version | 4 | 4 | 4 | 4 | 5 | 5 |
+ -------------------------------------------------------------- +
| Minor version | 0 | 10 | 90 | 0 | 0 | 1 |
+ -------------------------------------------------------------- +

Note: despiteCodeIt has been verified on all 32-bit versions of Windows, but Windows 95 and Windows NT 3.51 do not support Microsoft Visual Studio. NET or common language runtime.

Obtain windows Information
The system namespace contains a class named operatingsystem. The properties in the operatingsystem class provide the operating system information in use. The osversion attribute in the system. Environment class returns an operatingsystem object.

System. operatingsystem osinfo = system. environment. osversion;

Judgment Platform
The first step in determining the operating system is to identify the operating system in use. You can use the platformid attribute in the operatingsystem class to determine which operating system is in use.

For example, the value of the enumerated type property win32windows indicates one of the following operating systems:

Windows 95
Windows 98
Windows 98 Second Edition
Windows ME
Similarly, the value of the WINNT attribute specifies 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. win32nt:
{
// Code to determine specific version of Windows NT 3.51,
// Windows NT 4.0, Windows 2000, or Windows XP.
}
}

Determine the version of Windows 95, Windows 98, Windows 98, or Windows ME
If you want to determine the version of Windows 95, Windows 98, Windows 98, or Windows ME, you can analyze the Primary and Secondary versions.

// 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;

Determine the version of Windows NT, Windows 2000, or Windows XP
If you want to determine the version of Windows NT, Windows 2000, or Windows XP, you can also analyze the Primary and Secondary versions.

// Platform is Windows NT 3.51, Windows NT 4.0, Windows 2000,
// Or Windows XP.
Case System. platformid. win32nt:

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 ("Window 2000 ");
Else
Console. writeline ("Windows XP ");
Break;
} Break;

Compilation example
The next step is to compile a project to test the function:

Open a new C # console application in Visual Studio. NET. The class1.cs code window is opened by default.
Use the following code to replace all the codes in class1.cs :?
Using 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 platform.
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. win32nt:

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 ("Window 2000 ");
Else
Console. writeline ("Windows XP ");
Break;
} Break;
}
Console. Readline ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.