2016-11-18 65 views
1

私はC#を使用します。私は、OSの現在のバージョンを取得しよう:C#のWindows 10で現在のバージョンのOSを取得

OperatingSystem os = Environment.OSVersion; 
Version ver = os.Version; 

私はのWindows 10に乗る:6.2

しかし6.2は、私は以下のソリューション(How can I detect if my app is running on Windows 10)を見つけのWindows 8WindowsServer 2012Detect Windows version in .net

です。

static bool IsWindows10() 
{ 
    var reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion"); 
    string productName = (string)reg.GetValue("ProductName"); 
    return productName.StartsWith("Windows 10"); 
} 

これは、C#で、現在のバージョンを取得するための最良のの方法ですか?

+1

この記事をチェックしてください:http://stackoverflow.com/questions/6331826/get-os-version-friendly-name-in-c-sharp –

+1

@olgaマニフェスト+サポートされているOSのguidsを追加しましたか? – magicandre1981

答えて

3

がアプリケーションにapplication manifestを追加し、マニフェストへのWindows 8.1とWindows 10のsupportedOS Idを追加... OSについての情報を取得するために使用することができます。

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
     <application> 
      <!-- Windows 10 --> 
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> 
      <!-- Windows 8.1 --> 
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> 
     </application> 
    </compatibility> 

Environment.OSVersionは、正しいデータが含まWindows 8.1およびWindows 10では6.2でなく、Windows 8を実行していることを示します。これはchange since Windows 8.1です。

+0

ありがとう、それは動作します! – Olga

0

ここには、Microsoft公式のhow to get the System Versionを示すリンクがあります。それは実際に...それはC++でだからだから、基本的に、あなただけのWindows 10の部分を維持し、その後、C#のにこのコードを変換する必要があります

#include <windows.h> 
#include <stdio.h> 
#include <VersionHelpers.h> 

int 
__cdecl 
wmain(
    __in int argc, 
    __in_ecount(argc) PCWSTR argv[] 
    ) 
{ 
    UNREFERENCED_PARAMETER(argc); 
    UNREFERENCED_PARAMETER(argv); 
    if (IsWindows10OrGreater()) 
    { 
     printf("Windows10OrGreater\n"); 
    } 
} 

Version API Helper Functions

への呼び出しであり、あなたが好きなら読み取ろうコード、this one linkをチェックアウトすることができます。このDLLは

関連する問題