Getting the System Version
The following example uses the Version API Helper functions to determine the version of the current operating system, if it is a Server or Client release, and then displays this information to the console. If compatibility mode is in effect, the example displays the operating system selected for application compatibility.
Relying on version information is not the best way to test for a feature. Instead, refer to the documentation for the feature of interest. For more information on common techniques for feature detection, see Operating System Version.
#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 (IsWindowsXPOrGreater())
{
printf("XPOrGreater\n");
}
if (IsWindowsXPSP1OrGreater())
{
printf("XPSP1OrGreater\n");
}
if (IsWindowsXPSP2OrGreater())
{
printf("XPSP2OrGreater\n");
}
if (IsWindowsXPSP3OrGreater())
{
printf("XPSP3OrGreater\n");
}
if (IsWindowsVistaOrGreater())
{
printf("VistaOrGreater\n");
}
if (IsWindowsVistaSP1OrGreater())
{
printf("VistaSP1OrGreater\n");
}
if (IsWindowsVistaSP2OrGreater())
{
printf("VistaSP2OrGreater\n");
}
if (IsWindows7OrGreater())
{
printf("Windows7OrGreater\n");
}
if (IsWindows7SP1OrGreater())
{
printf("Windows7SP1OrGreater\n");
}
if (IsWindows8OrGreater())
{
printf("Windows8OrGreater\n");
}
if (IsWindows8Point1OrGreater())
{
printf("Windows8Point1OrGreater\n");
}
if (IsWindows10OrGreater())
{
printf("Windows10OrGreater\n");
}
if (IsWindowsServer())
{
printf("Server\n");
}
else
{
printf("Client\n");
}
}
Váš názor
https://aka.ms/ContentUserFeedback.
Připravujeme: V průběhu roku 2024 budeme postupně vyřazovat problémy z GitHub coby mechanismus zpětné vazby pro obsah a nahrazovat ho novým systémem zpětné vazby. Další informace naleznete v tématu:Odeslat a zobrazit názory pro