How to use Visual C # .NET to check Windows version [转]

zhaozj2021-02-16  95

Get a Windows version data to get the Windows system information judgment platform to determine the version 95, Windows 98, Windows 98 Second Edition or Windows ME version to determine the version of Windows NT, Windows 2000, or Windows XP compile

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

Overview This article describes how to check which operating system runs on your application. This article distinguishes 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 Windows XP. Gets Windows Version Data To check the operating 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 | --------------------------- ----------------------------------- | Main version number | 4 | 4 | 4 | 5 | 5 | ----------------------------------------------- ---------------- | Depth version number | 0 | 10 | 90 | 0 | 0 | 1 | --------------- -------------------------------------------------

Note: Although this code is verified on all 32-bit versions of Windows, Windows 95 and Windows NT 3.51 do not support Microsoft Visual Studio .NET or Common Language Runtime.

Gets Windows System Information In the System namespace contains a class named OperatingSystem. The properties in the OperatingSystem class provide operating system information being used. The OSVersion property in the System.Environment class returns an Operatingsystem object.

System.OperatingSystem Osinfo = System.environment.OSVERSION DISNVIRONFO = SYSTEM.ENVIRONMENT.OSVERSION;

The determination platform determines that the first step in the operating system is to identify which operating system is being used. You can use the PlatformID attribute in the OperatingSystem class to determine which operating system is in use.

For example, the enumerated type attribute Win32Windows value indicates one of the following operating systems:

Windows 95Windows 98Windows 98 Second EditionWindows Me Similarly, the WinNT property indicates the value of one of the following operating systems: Windows NT 3.51Windows NT 4.0Windows 2000Windows 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 Windows 95, Windows 98, Windows 98 Second Edition or Windows Me Version If you want to determine the version of Windows 95, Windows 98, Windows 98 Second Edition or Windows Me, you can analyze the primary version number and the private version number.

// 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 version number and the secure version number.

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

Compiling Sample Next is to compile a project to test the function: In Visual Studio .NET, open a new C # Console application. The Class1.cs code window will open by default. Replace the code in all class1.cs with the following code:? 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)

转载请注明原文地址:https://www.9cbs.com/read-12158.html

New Post(0)