C# 判断Windows版本及CPU位数

  1.   class  CheckWinVersion  
  2.     {  
  3.         int  getOSArchitecture()  
  4.         {  
  5.             string  pa = Environment.GetEnvironmentVariable( "PROCESSOR_ARCHITECTURE" );  
  6.             return  ((String.IsNullOrEmpty(pa) || String.Compare(pa, 0,  "x86" , 0, 3,  true ) == 0) ? 32 : 64);  
  7.         }  
  8.         string  getOSInfo()  
  9.         {  
  10.             //Get Operating system information.   
  11.             OperatingSystem os = Environment.OSVersion;  
  12.             //Get version information about the os.   
  13.             Version vs = os.Version;  
  14.   
  15.             //Variable to hold our return value   
  16.             string  operatingSystem =  "" ;  
  17.   
  18.             if  (os.Platform == PlatformID.Win32Windows)  
  19.             {  
  20.                 //This is a pre-NT version of Windows   
  21.                 switch  (vs.Minor)  
  22.                 {  
  23.                     case  0:  
  24.                         operatingSystem = "95" ;  
  25.                         break ;  
  26.                     case  10:  
  27.                         if  (vs.Revision.ToString() ==  "2222A" )  
  28.                             operatingSystem = "98SE" ;  
  29.                         else   
  30.                             operatingSystem = "98" ;  
  31.                         break ;  
  32.                     case  90:  
  33.                         operatingSystem = "Me" ;  
  34.                         break ;  
  35.                     default :  
  36.                         break ;  
  37.                 }  
  38.             }  
  39.             else   if  (os.Platform == PlatformID.Win32NT)  
  40.             {  
  41.                 switch  (vs.Major)  
  42.                 {  
  43.                     case  3:  
  44.                         operatingSystem = "NT 3.51" ;  
  45.                         break ;  
  46.                     case  4:  
  47.                         operatingSystem = "NT 4.0" ;  
  48.                         break ;  
  49.                     case  5:  
  50.                         if  (vs.Minor == 0)  
  51.                             operatingSystem = "2000" ;  
  52.                         else   
  53.                             operatingSystem = "XP" ;  
  54.                         break ;  
  55.                     case  6:  
  56.                         if  (vs.Minor == 0)  
  57.                             operatingSystem = "Vista" ;  
  58.                         else   
  59.                             operatingSystem = "7" ;  
  60.                         break ;  
  61.                     default :  
  62.                         break ;  
  63.                 }  
  64.             }  
  65.             //Make sure we actually got something in our OS check   
  66.             //We don't want to just return " Service Pack 2" or " 32-bit"   
  67.             //That information is useless without the OS version.   
  68.             if  (operatingSystem !=  "" )  
  69.             {  
  70.                 //Got something.  Let's prepend "Windows" and get more info.   
  71.                 operatingSystem = "Windows "  + operatingSystem;  
  72.                 //See if there's a service pack installed.   
  73.                 if  (os.ServicePack !=  "" )  
  74.                 {  
  75.                     //Append it to the OS name.  i.e. "Windows XP Service Pack 3"   
  76.                     operatingSystem += " "  + os.ServicePack;  
  77.                 }  
  78.                 //Append the OS architecture.  i.e. "Windows XP Service Pack 3 32-bit"   
  79.                 operatingSystem += " "  + getOSArchitecture().ToString() +  "-bit" ;  
  80.             }  
  81.             //Return the information we've gathered.   
  82.             return  operatingSystem;  
  83.         }  
  84.     } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值