The program works in compatibility mode

Is there a C ++. NET function that I can call that will detect if my program is running in compatibility mode? If not, can someone show me the code for one? Thank.

For instance:

Download programs Check compatibility mode if true, then exit else run

+5
source share
3 answers

From another forum

After several Google searches in vain, I decided to experiment myself. I found that compatibility for each executable is stored - as I thought it would be - in the Windows registry.

The key in which the settings are stored is
HKEY_CURRENT_USER \ Software \ Microsoft \ Windows NT \ CurrentVersion \ AppCompatFlags \ Layers

, , - , - .

, : WIN95 WIN98 NT4SP5
WIN2000 256COLOR 640X480
DISABLETHEMES DISABLECICERO

( ), . , .. ( ). .

, . , (, "C:\path\executable.exe" ) 256 , "C:\path\executable.exe" ( , ) [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers], , "256COLOR". Windows 98/ME, "WIN98 256COLOR".

, . , . , . , "256COLOR" . , "WIN95" "WIN98" "NT4SP5" "WIN2000" , .

+8

, GetVersionEx, kernel32.dll. GetVersionEx , "". , .

+2

"" . , , , , , . , . . , API .

typedef VOID (NTAPI* TRtlGetNtVersionNumbers)(LPDWORD pdwMajorVersion, LPDWORD pdwMinorVersion, LPDWORD pdwBuildNumber);

bool IsRunningCompatMode()
{
    TRtlGetNtVersionNumbers RtlGetNtVersionNumbers = (TRtlGetNtVersionNumbers)GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlGetNtVersionNumbers");

    assert(RtlGetNtVersionNumbers);

    if(RtlGetNtVersionNumbers)
    {
        OSVERSIONINFO osInfo = {0};
        osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        GetVersionEx(&osInfo);

        DWORD dwMajorVersion;
        DWORD dwMinorVersion;
        DWORD dwBuildNumber;

        RtlGetNtVersionNumbers(&dwMajorVersion, &dwMinorVersion, &dwBuildNumber);

        dwBuildNumber &= 0x0000FFFF;

        if(osInfo.dwBuildNumber != dwBuildNumber)
        {
            return true;
        }
    }
    return false;
};
+1
source

All Articles