2017-11-10 8 views
-1

開発マシンでWindows 10を実行しています。 10. Tried thisのメジャーバージョンを返すようにOSバージョンを取得しようとしましたが、System::Environment::OSVersion->VersionStringで環境変数も試しました。どちらもMicrosoft Windows NT 6.2.9200です。 Windows 7マシンで実行可能ファイルをテストしたところ、6.1.*(正しい)が得られました。MSVC OSVersionが不正なバージョンを返す

私は正しい結果を得るPowerShellでこれを実行している:私は(私は

#include <Windows.h> 
#include <iostream> 

using namespace std; 

int main(int argc, char **argv, char** envp) { 
    printf("Current compiler version is ... %d\n", _MSC_VER); 
    printf("Current compiler full version is ... %d\n", _MSC_FULL_VER); 
    printf("Current OSVersion is ... %s\n\n", System::Environment::OSVersion->VersionString); 

    char** env; 
    for (env = envp; *env != 0; env++) 
    { 
     char* thisEnv = *env; 
     printf("%s\n", thisEnv); 
    } 

    cin.ignore(); 
    cin.ignore(); 

    return 0; 
} 

はそれを結果...同じ環境変数のロジックを使用してVisual StudioでテストC++プログラムを書いた

PS Z:\> [System.Environment]::OSVersion.Version 

Major Minor Build Revision 
----- ----- ----- -------- 
10  0  14393 0 

を...

Current compiler version is ... 1900 
Current compiler full version is ... 190024215 
Current OSVersion is ... Microsoft Windows NT 6.2.9200.0 

... 
OS=Windows_NT 

上記のテストpターゲットプラットフォームが10.0.14393.0と設定されています。

なぜ私のOSはWindows 8だと思いますか?

仕様:

  • のWindows 10
  • バージョン10.0.14393 14393
  • のVisual Studio 2015(C++プロジェクト)
    • ターゲットプラットフォーム10.0.14393.0
  • PowerShellを構築しますバージョン5.1
+0

を参照してください;' (https://stackoverflow.com/q/1452721/2176813)、決してそれを使用しないでください。 – tambre

+1

[app.manifestをプロジェクトに追加し、8.1および10のサポートされているOS GUIDを追加](https://stackoverflow.com/a/40681525/1466046)。今それは動作します。 – magicandre1981

+2

[C#のWindows 10で現在のバージョンのOSを取得]の可能な複製(https://stackoverflow.com/questions/40672109/get-current-version-os-in-windows-10-in-c-sharp) – magicandre1981

答えて

0

これは、すべてのWin32デスクトップアプリケーションのWindows 8.1以降でデフォルトで有効にされているGetVersionExおよびVerifyVersionInfo関数が 'バージョンの嘘'を持つように設計されています。

あなたは適切な互換性のGUIDを含み、あなたのEXEに埋め込まれたマニフェストを追加することにより、「バージョン嘘」のアプリケーションを制御します。

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
     <application> 
      <!-- Windows Vista --> 
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
      <!-- Windows 7 --> 
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> 
      <!-- Windows 8 --> 
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> 
      <!-- Windows 8.1 --> 
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> 
      <!-- Windows 10 --> 
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> 
     </application> 
    </compatibility> 
</assembly> 

は、std名前空間を使用して `[MSDNManifest Madness

+0

Didこれは動作しますが、警告が表示されます(これもまた嘘です) - マニフェストのオーサリング警告81010002:名前空間 "urn:schemas-microsoft-com:compatibility.v1"の認識できない要素 "compatibility"互換性タグが実際に動作し、正しいWindowsバージョンを返すことができたので、私はそれがうそだと主張します。これが何であるか、あるいは私がそれをどのように取り除くことができるかについてのあらゆる考え? –

+0

これは、使用しているマニフェストツールのバージョン( '' MT.EXE'')に依存します。この警告は、最近のものを使用している場合は発生しません。プロジェクトのツールパスを調べて、使用しているパスを特定します。 –

関連する問題