以 Windows 應用程式為目標

在 Windows 8.1 和更新版本中,GetVersion 和 GetVersionEx函式已被取代。 從Windows 10起,VerifyVersionInfo函式也已被取代。 您仍然可以呼叫已被取代的函式,但如果您的應用程式未特別以Windows 8.1或更新版本為目標,則函式會傳回Windows 8版本 (6.2) 。

注意

GetVersionGetVersionExVerifyVersionInfoVersion Helper 函式 僅適用于傳統型應用程式。 通用 Windows 應用程式可以使用 AnalyticsInfo.VersionInfo 屬性進行遙測和診斷記錄。

為了讓您的應用程式以Windows 8.1或更新版本為目標,您必須為應用程式的可執行檔包含應用程式 (可執行檔) 資訊清單。 然後,在資訊清單的相容性 > 區段中,您必須為每個您想要宣告應用程式支援的 Windows 版本新增支援的OS 元素。 <><

下列範例顯示應用程式的應用程式資訊清單檔案,可支援 Windows Vista 的所有 Windows 版本到Windows 11:

<!-- example.exe.manifest -->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <assemblyIdentity
        type="win32"
        name="Contoso.ExampleApplication.ExampleBinary"
        version="1.2.3.4"
        processorArchitecture="x86"
    />
    <description>Contoso Example Application</description>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- Windows 10 and Windows 11 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
        </application>
    </compatibility>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <!--
                  UAC settings:
                  - app should run at same integrity level as calling process
                  - app does not need to manipulate windows belonging to
                    higher-integrity-level processes
                  -->
                <requestedExecutionLevel
                    level="asInvoker"
                    uiAccess="false"
                />   
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

在先前的作業系統上執行應用程式時,在應用程式資訊清單中宣告對Windows 8.1或更新版本中的支援不會有任何作用。

上述應用程式資訊清單也包含trustInfo > 區 <,指定系統在使用者帳戶控制 (UAC) 時應如何處理它。 新增 trustInfo 並不重要,但強烈建議您,即使您的應用程式不需要任何特定的 UAC 相關行為也一樣。 特別是,如果您完全不新增 trustInfo ,則應用程式的 32 位 x86 版本會受限於 UAC 檔案虛擬化,這可允許寫入系統管理員許可權的資料夾,例如 Windows 系統資料夾在失敗時成功,但將它們重新導向至使用者特定的 「VirtualStore」 資料夾。