27

I think the title is self explanatory... I'm writing an application in C++ and I need to determine at runtime if I'm running under Wine (to change the bahavior a little in order to avoid a specific Wine bug). Is there a programmer-friendly way or should I fiddle with running processes?

kingofx87
  • 271
  • 3
  • 3

2 Answers2

16

This answer is just a copy of user1457056's comment. Since links often die, answers occasionally become useless. I have copied the link content here in order to preserve this useful answer:

#include <windows.h>
#include <stdio.h>
int main(void)
{
    static const char *(CDECL *pwine_get_version)(void);
    HMODULE hntdll = GetModuleHandle("ntdll.dll");
    if(!hntdll)
    {
        puts("Not running on NT.");
        return 1;
    }

    pwine_get_version = (void *)GetProcAddress(hntdll, "wine_get_version");
    if(pwine_get_version)
    {
        printf("Running on Wine... %s\n",pwine_get_version());
    }
    else
    {
        puts("did not detect Wine.");
    }

    return 0;
}
Gabriel Ravier
  • 358
  • 1
  • 6
  • 17
Christoph Meißner
  • 1,511
  • 2
  • 21
  • 40
11

There are many Wine specific registry entries:

HKEY_CURRENT_USER\Software\Wine
HKEY_LOCAL_MACHINE\Software\Wine

Checking if a registry key exists has the answer of how to check for these Wine-specific registry keys.

Community
  • 1
  • 1
Šimon Tóth
  • 35,456
  • 20
  • 106
  • 151
  • 2
    This is a bad solution, because anyone could create these registry keys on Windows as well. – Mario Jan 28 '23 at 10:22