Detecting a programm runs using Wine

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
felix
Level 2
Level 2
Posts: 45
Joined: Thu Feb 28, 2008 10:04 am

Detecting a programm runs using Wine

Post by felix »

On Tue, Feb 10, 2009 at 02:02:35PM +0000, David Gerard wrote:
2009/2/9 Darragh Bailey <[email protected]>:
Wine does not support detecting of wine, therefore whatever method is
used, the wine developers may well change this in the future to suit.
Hence the detection method no longer works and the app now breaks.
Will Wine be abandoning its own set of registry keys?

http://wiki.winehq.org/UsefulRegistryKeys

Will detecting HKEY_CURRENT_USER\Software\Wine stop working at some
point in the future?
Probably not, but you cannot depend on it, as it's not supported. The
developers may choose to rename the registry keys at sometime in the
future.

--
Darragh

"Nothing is foolproof to a sufficiently talented fool."
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: Detecting a programm runs using Wine

Post by vitamin »

David Gerard wrote:Will Wine be abandoning its own set of registry keys?
Doubt. But what will prevent user from creating those keys on windows?

If you need a sure way to detect wine - look for any of internal Wine exports from ntdll with GetProcAddress().
JonDoe
Newbie
Newbie
Posts: 1
Joined: Sat Feb 14, 2009 10:02 pm

Post by JonDoe »

Hi,

I have also been searching for a way to detect if my application is running under wine. As I haven´t found an appropriate solution I came to the following solution. It may not be perfect and there is no guarantee that it will always be working but I think it is a good approach.

Code: Select all

BOOL CMyClass::IsWine() 
{
	CString csRet;
	BOOL fRet = FALSE;
	CString csEntry = _T("ProductName");

	HMODULE hLib = LoadLibrary(_T("ntdll"));

	if (hLib != NULL)
	{
		HRSRC hVersion = FindResource( hLib, 
		MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
		if (hVersion != NULL)
		{
			HGLOBAL hGlobal = LoadResource( hLib, hVersion ); 
			if ( hGlobal != NULL)  
			{  
				LPVOID versionInfo  = LockResource(hGlobal);  
				if (versionInfo != NULL)
				{
					DWORD vLen,langD;
					BOOL retVal;    

					LPVOID retbuf=NULL;

					TCHAR fileEntry[256];

					_stprintf(fileEntry,_T("\\VarFileInfo\\Translation"));
					retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
					if (retVal && vLen==4) 
					{
						memcpy(&langD,retbuf,4);            
						_stprintf(fileEntry, _T("\\StringFileInfo\\%02X%02X%02X%02X\\%s"),
						(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24, 
						(langD & 0xff0000)>>16, csEntry);            
					}
					else 
					_stprintf(fileEntry, _T("\\StringFileInfo\\%04X04B0\\%s"), 
					GetUserDefaultLangID(), csEntry);

					if (VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen)) 
					{
						csRet = (TCHAR*)retbuf;

						csRet.MakeLower();

						if(0 <= csRet.Find(_T("wine")))
							fRet = TRUE;
					}
				}
			}

			UnlockResource( hGlobal );  
			FreeResource( hGlobal );  
			FreeLibrary(hLib);
		}
	}
	return fRet;
}
This code is mainly based on a publication on www.codeproject.com by luetz: http://www.codeproject.com/KB/cpp/GetLo ... play=Print.

I simply read the product name of the ntdll.dll which is "Wine" when running under wine.

Hope this helps, JonDoe
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Post by vitamin »

JonDoe wrote:I have also been searching for a way to detect if my application is running under wine. As I haven´t found an appropriate solution I came to the following solution.
It's a really bad way to detect Wine by looking at resources.

If you really want to have a reliable sure way to detect Wine - look for Wine specific export(s) from that dll. But as mentioned before, make it a user overridable in case Wine gets fixed, or developers want to actually use your app to verify correct functionality.
Locked