简体   繁体   中英

Windows 8.1 version returned as 6.2 (Win 8.0) when not elevated, but 6.3 (Win 8.1) when elevated. Why?

Calling Environment.OSVersion.Version in my C# application running on Windows 8.1 returns 6.2 (which is Windows 8) when I run as a normal (non-administrator) account, but 6.3 (Windows 8.1) when I run as administrator.

My manifest does include compatibility for Windows 8.1 as per this article http://msdn.microsoft.com/en-us/library/windows/desktop/dn481241%28v=vs.85%29.aspx , but I only get the correct version number when I run with elevated privileges. Any idea why?

My manifest:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>

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

Version numbers: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx

Similar questions:

Why OS.Version reports Windows 8.0 for Windows 8.1?

How can I detect Windows 8.1 in a Desktop application

OK - maybe I can narrow this problem down. If I run my application from Visual Studio with the debugger attached I see this problem (ie it reports 6.2 = Windows 8). If, however, I start the application without debugging (no vshost) then I do not see the problem (ie it reports 6.3 = Windows 8.1).

Is the problem that the manifest is built into my application's exe, but the executing process is the vshost wrapper, which does not have a manifest that reports compatibility with Windows 8.1? That makes sense to me, but it's odd behaviour. It effectively means that when debugging your app.manifest file is useless.

I cannot find any supporting evidence from Microsoft, but debugging my application with and without the hosting process results in different behaviours. My conclusion is that the hosting process has its own manifest, which is different your application's manifest. As such the operating system will not "see" at least some of your manifest settings such as operating system compatibility.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM