????? C# ?? ????? ?? Windows ?? ??????? ?? ???????? ???? ????

???? ?????? ???? ??????
???? ID: 304283 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ??? ?? ??? ???? ????????? ???? ?? ?? ??? ?? ???????? ?????? ?? ????? ??? ?? ?????? ?? ???? ???? ????????? ?? ??? ?? ?? ???????? ???? ????? ?? ???? Microsoft Windows 95, Microsoft Windows 98, Microsoft Windows 98 ????? ???????, Microsoft Windows Millennium ??????? (Windows Me), Microsoft Windows NT 3.51, Microsoft Windows NT 4.0, Microsoft Windows 2000 ?? Microsoft Windows XP ?? ??? differentiates ???

??????????

  • Microsoft Visual C# .NET
  • Microsoft Visual C# 2005 ?? Visual C# 2008
  • ????? C# ???????????? ?? ??????? ???? ???

Windows ??????? ???? ??????? ????

?????? ?? ?? ??? ???????? ?????? ?? ????????? ????, ????? ???? ??????? ????:
+--------------------------------------------------------------+
|           |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     | 1     |
+--------------------------------------------------------------+
				
???:: Although the code in this article is verified for use with all 32-bit versions of Windows, Windows 95 and Windows NT 3.51 do not support Microsoft Visual Studio .NET or the common language runtime.

Obtain the Operating System Information

The??????namespace contains a class namedOperatingSystem. The properties for theOperatingSystemclass provide the necessary information about the operating system that is in use. TheOSVersion?? ???System.Environmentclass returns anOperatingSystem???????? ???
    System.OperatingSystem osInfo = System.Environment.OSVersion;
				

??????????? ????????? ????

???? ??? ?? ??????? ????????? ???OperatingSystem????? ??? ?? ?? ?????????? ????????? ???? ?? ??? ??????? ??? ?? ????? ?? ???? ???PlatformID?? ???OperatingSystem????? ??? ?? ?? ?????????? ????????? ???? ?? ??? ?????

For example, the enumerated value of theWin32Windows??? ????? ???????? ???????? ??? ?? ?? ?? ????? ???? ??:
  • Windows 95
  • Windows 98
  • Windows 98 Second Edition
  • Windows Me
??? ???,WinNT??? ????? ???????? ???????? ??? ?? ?? ?? ????? ???? ??:
  • 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.
               }
           
         }
				

?? ????????? ??????? ??????? ?? Windows 95, Windows 98, Windows 98 ????? ???????, ?? Windows Me

??? ?? ?? ????????? ?? ?? Windows 95, Windows 98, Windows 98 ????? ??????? ?? Windows Me ?????????? ??, ?? ?? ?? ???? ??? ???????? ??????? ??????? ?? ???????? ???? ?? ??? ??? ?? ???? ????????
    // 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;
				

Windows NT, Windows 2000 ?? Windows XP ?? ??????? ??????? ?? ????????

??? ?? ?? ????????? ?? ?? Windows NT 3.51, Windows NT 4.0, Windows 2000 ?? Windows XP ?????????? ??, ?? ?? ?? ???? ??? ???????? ??????? ??????? ?? ???????? ???? ?? ??? ??? ?? ???? ????????
    // 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;
				

????? ?????

????? ????? ?? ??????? ???????? ?? ?? ?? ??????????? ????????? ???? ?? ?? ?????:
  1. Visual Studio .NET, ??? ?? ??? C# ????? ????????? ?????? ???????? ??? ?? Class1.cs ?? ??? ??? ????? ????? ???

    ???:Visual Studio 2005 ?? Visual Studio 2008 ???, ??????? ????? ?? Program.cs. ?? ???-????? ?? ???? ???Program.cs??? ????? ????? ???
  2. ????? ????? ??? ?? ??? ??? ??? 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("Windows 2000");
                         else
                            Console.WriteLine("Windows XP");
                         break;
                   }break;
             }
             Console.ReadLine ();
          }
       }
    }
    					
  3. ????????? ?? ????? ?? ??? CTRL + F5 ?????? ??? ???? ?? Windows ?? ??????? ?????? ????? ??? ????? ???

???

???? ID: 304283 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft Visual C# 2005
  • Microsoft Visual C# 2008 Express Edition
??????: 
kbhowtomaster kbprod2web kbmt KB304283 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:304283

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com