Exemplo n.º 1
0
bool IsWinVerEqual(WORD OsVer)
{
	OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(OsVer), LOBYTE(OsVer)};
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL), VER_MINORVERSION, VER_EQUAL);
	BOOL ibIsWinOrHigher = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);
	return (ibIsWinOrHigher != FALSE);
}
Exemplo n.º 2
0
bool IsUserAdmin()
{
	// No need to show any "Shield" on XP or 2k
	_ASSERTE(_WIN32_WINNT_VISTA==0x600);
	OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA)};
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
	if (!VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask))
		return false;

	BOOL b;
	SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
	PSID AdministratorsGroup;
	b = AllocateAndInitializeSid(
			&NtAuthority,
			2,
			SECURITY_BUILTIN_DOMAIN_RID,
			DOMAIN_ALIAS_RID_ADMINS,
			0, 0, 0, 0, 0, 0,
			&AdministratorsGroup);

	if (b)
	{
		if (!CheckTokenMembership(NULL, AdministratorsGroup, &b))
		{
			b = FALSE;
		}

		FreeSid(AdministratorsGroup);
	}

	return (b ? true : false);
}
Exemplo n.º 3
0
void Curl_sndbufset(curl_socket_t sockfd)
{
  int val = CURL_MAX_WRITE_SIZE + 32;
  int curval = 0;
  int curlen = sizeof(curval);
  DWORD majorVersion = 6;

  static int detectOsState = DETECT_OS_NONE;

  if(detectOsState == DETECT_OS_NONE) {
#if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_WIN2K) || \
    (_WIN32_WINNT < _WIN32_WINNT_WIN2K)
    OSVERSIONINFO osver;

    memset(&osver, 0, sizeof(osver));
    osver.dwOSVersionInfoSize = sizeof(osver);

    detectOsState = DETECT_OS_PREVISTA;
    if(GetVersionEx(&osver)) {
      if(osver.dwMajorVersion >= majorVersion)
        detectOsState = DETECT_OS_VISTA_OR_LATER;
    }
#elif defined(CURL_WINDOWS_APP)
    (void)majorVersion;
    detectOsState = DETECT_OS_VISTA_OR_LATER;
#else
    ULONGLONG cm;
    OSVERSIONINFOEX osver;

    memset(&osver, 0, sizeof(osver));
    osver.dwOSVersionInfoSize = sizeof(osver);
    osver.dwMajorVersion = majorVersion;

    cm = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
    cm = VerSetConditionMask(cm, VER_MINORVERSION, VER_GREATER_EQUAL);
    cm = VerSetConditionMask(cm, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
    cm = VerSetConditionMask(cm, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);

    if(VerifyVersionInfo(&osver, (VER_MAJORVERSION | VER_MINORVERSION |
                                  VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR),
                         cm))
      detectOsState = DETECT_OS_VISTA_OR_LATER;
    else
      detectOsState = DETECT_OS_PREVISTA;
#endif
  }

  if(detectOsState == DETECT_OS_VISTA_OR_LATER)
    return;

  if(getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&curval, &curlen) == 0)
    if(curval > val)
      return;

  setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (const char *)&val, sizeof(val));
}
Exemplo n.º 4
0
bool IsWin10()
{
	static int ibIsWin10 = 0;
	if (!ibIsWin10)
	{
		#define _WIN32_WINNT_WIN10 0x604
		OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_WIN10), LOBYTE(_WIN32_WINNT_WIN10)};
		DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
		ibIsWin10 = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) ? 1 : -1;
	}
	return (ibIsWin10 == 1);
}
Exemplo n.º 5
0
// Checks whether we are on at least the specified build of Windows 10
//
BOOL _glfwIsWindows10BuildOrGreaterWin32(WORD build)
{
    OSVERSIONINFOEXW osvi = { sizeof(osvi), 10, 0, build };
    DWORD mask = VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER;
    ULONGLONG cond = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
    cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);
    cond = VerSetConditionMask(cond, VER_BUILDNUMBER, VER_GREATER_EQUAL);
    // HACK: Use RtlVerifyVersionInfo instead of VerifyVersionInfoW as the
    //       latter lies unless the user knew to embedd a non-default manifest
    //       announcing support for Windows 10 via supportedOS GUID
    return RtlVerifyVersionInfo(&osvi, mask, cond) == 0;
}
Exemplo n.º 6
0
//
// IsVistaOrAbove
//
bool IsVistaOrAbove()
{
    OSVERSIONINFOEX ovi = { 0 };
    ovi.dwOSVersionInfoSize = sizeof(ovi);
    ovi.dwMajorVersion = 6;
    ovi.dwPlatformId = VER_PLATFORM_WIN32_NT;

    ULONGLONG uConditionMask = 0;
    uConditionMask = VerSetConditionMask(uConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
    uConditionMask = VerSetConditionMask(uConditionMask, VER_PLATFORMID, VER_EQUAL);
    return VerifyVersionInfo(&ovi, VER_MAJORVERSION | VER_PLATFORMID, uConditionMask) != FALSE;
}
Exemplo n.º 7
0
static bool isWindowsVersionOrGreater(uint16 majorVersion, uint16 minorVersion) {
	OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 };

	DWORDLONG condition =
		VerSetConditionMask(VerSetConditionMask(
			0, VER_MAJORVERSION, VER_GREATER_EQUAL),
			   VER_MINORVERSION, VER_GREATER_EQUAL);

	osvi.dwMajorVersion = majorVersion;
	osvi.dwMinorVersion = minorVersion;

	return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, condition) != 0;
}
Exemplo n.º 8
0
// Only Windows 2000
bool IsWin2kEql()
{
	static int ibIsWin2K = 0;
	if (!ibIsWin2K)
	{
		OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_WIN2K), LOBYTE(_WIN32_WINNT_WIN2K)};
		DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0,
			VER_MAJORVERSION, VER_EQUAL),
			VER_MINORVERSION, VER_EQUAL);
		ibIsWin2K = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) ? 1 : -1;;
	}
	return (ibIsWin2K == 1);
}
Exemplo n.º 9
0
	BOOL LoadAdvApi()
	{
		if (mh_AdvApi)
		{
			return TRUE;
		}

		for (int i = 0; i <= 1; i++)
		{
			if (i == 0)
			{
				_ASSERTE(_WIN32_WINNT_WIN7==0x601);
				OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7)};
				DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
				if (!_VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask))
					continue; // в Vista и ниже "KernelBase.dll" еще не было
				mh_AdvApi = LoadLibrary(L"KernelBase.dll");
			}
			else
			{
				mh_AdvApi = LoadLibrary(L"Advapi32.dll");
			}
			
			if (!mh_AdvApi)
			{
				#ifdef _DEBUG
				mn_LastError = GetLastError();
				#endif
				return FALSE;
			}

			AddAccessAllowedAce = (AddAccessAllowedAce_t)GetProcAddress(mh_AdvApi, "AddAccessAllowedAce");
			AddAccessDeniedAce = (AddAccessDeniedAce_t)GetProcAddress(mh_AdvApi, "AddAccessDeniedAce");
			AllocateAndInitializeSid = (AllocateAndInitializeSid_t)GetProcAddress(mh_AdvApi, "AllocateAndInitializeSid");
			GetLengthSid = (GetLengthSid_t)GetProcAddress(mh_AdvApi, "GetLengthSid");
			InitializeAcl = (InitializeAcl_t)GetProcAddress(mh_AdvApi, "InitializeAcl");
			InitializeSecurityDescriptor = (InitializeSecurityDescriptor_t)GetProcAddress(mh_AdvApi, "InitializeSecurityDescriptor");
			SetSecurityDescriptorDacl = (SetSecurityDescriptorDacl_t)GetProcAddress(mh_AdvApi, "SetSecurityDescriptorDacl");

			if (AddAccessAllowedAce && AddAccessDeniedAce && AllocateAndInitializeSid &&
				GetLengthSid && InitializeAcl && InitializeSecurityDescriptor && SetSecurityDescriptorDacl)
			{
				return TRUE;
			}

	    	UnloadAdvApi();
	    	return FALSE;
	    }
		return FALSE;
	}
Exemplo n.º 10
0
bool IsHwFullScreenAvailable()
{
	if (IsWindows64())
		return false;

	// HW FullScreen was available in Win2k & WinXP (32bit)
	_ASSERTE(_WIN32_WINNT_VISTA==0x600);
	OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA)};
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
	if (VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask))
		return false; // Vista or higher - not available
	else
		return true;
}
Exemplo n.º 11
0
 inline bool IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
 {
	OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, { 0 }, 0, 0 };
	DWORDLONG const dwlConditionMask = VerSetConditionMask(
		VerSetConditionMask(
		VerSetConditionMask(
		0, VER_MAJORVERSION, VER_GREATER_EQUAL),
		VER_MINORVERSION, VER_GREATER_EQUAL),
		VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
	osvi.dwMajorVersion = wMajorVersion;
	osvi.dwMinorVersion = wMinorVersion;
	osvi.wServicePackMajor = wServicePackMajor;
	return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
 }
Exemplo n.º 12
0
// Mostly taken from the Windows 8.1 SDK's VersionHelpers.h.
static bool IsWindowsVistaOrGreater()
{
	OSVERSIONINFOEXW osvi = {sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0};

	osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_VISTA);
	osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_VISTA);
	osvi.wServicePackMajor = 0;

	DWORDLONG majorversionmask = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
	DWORDLONG versionmask = VerSetConditionMask(majorversionmask, VER_MINORVERSION, VER_GREATER_EQUAL);
	DWORDLONG mask = VerSetConditionMask(versionmask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

	return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, mask) != FALSE;
}
Exemplo n.º 13
0
// WinXP SP1 or higher
bool IsWinXPSP1()
{
	static int ibIsWinXPSP1 = 0;
	if (!ibIsWinXPSP1)
	{
		OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_WINXP), LOBYTE(_WIN32_WINNT_WINXP)};
		osvi.wServicePackMajor = 1;
		DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(VerSetConditionMask(0,
			VER_MAJORVERSION, VER_GREATER_EQUAL),
			VER_MINORVERSION, VER_GREATER_EQUAL),
			VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
		ibIsWinXPSP1 = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) ? 1 : -1;;
	}
	return (ibIsWinXPSP1 == 1);
}
Exemplo n.º 14
0
BOOL IsWindowsVersion(
					  WORD wMajorVersion,
					  WORD wMinorVersion
					  )
{
	OSVERSIONINFOEX version_info = { 0 };
	version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	version_info.dwMajorVersion = wMajorVersion;
	version_info.dwMinorVersion = wMinorVersion;

	ULONGLONG mask = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
	mask = VerSetConditionMask(mask, VER_MINORVERSION, VER_EQUAL);

	return VerifyVersionInfo(&version_info, VER_MAJORVERSION | VER_MINORVERSION, mask);
}
Exemplo n.º 15
0
int
isc_win32os_versioncheck(unsigned int major, unsigned int minor,
			 unsigned int spmajor, unsigned int spminor)
{
	OSVERSIONINFOEX osVer;
	DWORD typeMask;
	ULONGLONG conditionMask;

	memset(&osVer, 0, sizeof(OSVERSIONINFOEX));
	osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	typeMask = 0;
	conditionMask = 0;

	/* Optimistic: likely greater */
	osVer.dwMajorVersion = major;
	typeMask |= VER_MAJORVERSION;
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_MAJORVERSION,
					    VER_GREATER);
	osVer.dwMinorVersion = minor;
	typeMask |= VER_MINORVERSION;
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_MINORVERSION,
					    VER_GREATER);
	osVer.wServicePackMajor = spmajor;
	typeMask |= VER_SERVICEPACKMAJOR;
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_SERVICEPACKMAJOR,
					    VER_GREATER);
	osVer.wServicePackMinor = spminor;
	typeMask |= VER_SERVICEPACKMINOR;
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_SERVICEPACKMINOR,
					    VER_GREATER);
	if (VerifyVersionInfo(&osVer, typeMask, conditionMask))
		return (1);

	/* Failed: retry with equal */
	conditionMask = 0;
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_MAJORVERSION,
					    VER_EQUAL);
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_MINORVERSION,
					    VER_EQUAL);
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_SERVICEPACKMAJOR,
					    VER_EQUAL);
	conditionMask = VerSetConditionMask(conditionMask,
					    VER_SERVICEPACKMINOR,
					    VER_EQUAL);
	if (VerifyVersionInfo(&osVer, typeMask, conditionMask))
		return (0);
	else
		return (-1);
}
Exemplo n.º 16
0
VERSIONHELPERAPI
IsWindowsServer()
{
	OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0, 0, VER_NT_WORKSTATION };
	DWORDLONG        const dwlConditionMask = VerSetConditionMask(0, VER_PRODUCT_TYPE, VER_EQUAL);

	return !VerifyVersionInfoW(&osvi, VER_PRODUCT_TYPE, dwlConditionMask);
}
Exemplo n.º 17
0
static
int is_winxp_or_later(void)
{
    OSVERSIONINFOEX osv;
    DWORDLONG cond;

    memset(&osv, 0, sizeof(osv));
    osv.dwOSVersionInfoSize = sizeof(osv);
    osv.dwMajorVersion = 5;
    osv.dwMinorVersion = 1;

    cond = 0;
    cond = VerSetConditionMask(cond, VER_MAJORVERSION, VER_GREATER_EQUAL);
    cond = VerSetConditionMask(cond, VER_MINORVERSION, VER_GREATER_EQUAL);

    return VerifyVersionInfo(&osv, VER_MAJORVERSION | VER_MINORVERSION, cond);
}
Exemplo n.º 18
0
BOOL WINAPI IsWindowsVersionOrGreater(
                                      WORD wMajorVersion,
                                      WORD wMinorVersion,
                                      WORD wServicePackMajor
                                      )
{
    OSVERSIONINFOEX version_info = { 0 };
    version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    version_info.dwMajorVersion = wMajorVersion;
    version_info.dwMinorVersion = wMinorVersion;
    version_info.wServicePackMajor = wServicePackMajor;

    ULONGLONG mask = VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL);
    mask = VerSetConditionMask(mask, VER_MINORVERSION, VER_GREATER_EQUAL);
    mask = VerSetConditionMask(mask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

    return VerifyVersionInfo(&version_info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, mask);
}
Exemplo n.º 19
0
bool BrowserFactory::IsWindowsVersionOrGreater(unsigned short major_version,
                                               unsigned short minor_version,
                                               unsigned short service_pack) {
  OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
  DWORDLONG        const dwlConditionMask = VerSetConditionMask(
    VerSetConditionMask(
      VerSetConditionMask(
        0, VER_MAJORVERSION, VER_GREATER_EQUAL),
      VER_MINORVERSION, VER_GREATER_EQUAL),
    VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

  osvi.dwMajorVersion = major_version;
  osvi.dwMinorVersion = minor_version;
  osvi.wServicePackMajor = service_pack;

  return VerifyVersionInfoW(&osvi,
                            VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
                            dwlConditionMask) != FALSE;
}
Exemplo n.º 20
0
static BOOL
IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
{
    OSVERSIONINFOEXW osvi;
    DWORDLONG const dwlConditionMask = VerSetConditionMask(
        VerSetConditionMask(
        VerSetConditionMask(
        0, VER_MAJORVERSION, VER_GREATER_EQUAL ),
        VER_MINORVERSION, VER_GREATER_EQUAL ),
        VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL );

    SDL_zero(osvi);
    osvi.dwOSVersionInfoSize = sizeof(osvi);
    osvi.dwMajorVersion = wMajorVersion;
    osvi.dwMinorVersion = wMinorVersion;
    osvi.wServicePackMajor = wServicePackMajor;

    return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE;
}
Exemplo n.º 21
0
void DebugVersionTest()
{
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);

	_ASSERTE(_WIN32_WINNT_WIN7==0x601);
	OSVERSIONINFOEXW osvi7 = {sizeof(osvi7), HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7)};
	bool bWin7 = VerifyVersionInfoW(&osvi7, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != 0;

	_ASSERTE(_WIN32_WINNT_VISTA==0x600);
	OSVERSIONINFOEXW osvi6 = {sizeof(osvi6), HIBYTE(_WIN32_WINNT_VISTA), LOBYTE(_WIN32_WINNT_VISTA)};
	bool bWin6 = VerifyVersionInfoW(&osvi6, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != 0;

	OSVERSIONINFOW osv = {sizeof(OSVERSIONINFOW)};
	GetVersionExW(&osv);
	bool bVerWin7 = ((osv.dwMajorVersion > 6) || ((osv.dwMajorVersion == 6) && (osv.dwMinorVersion >= 1)));
	bool bVerWin6 = (osv.dwMajorVersion >= 6);

	_ASSERTE(bWin7 == bVerWin7);
	_ASSERTE(bWin6 == bVerWin6);
}
Exemplo n.º 22
0
// Only 5.x family (Win2k, WinXP, Win 2003 server)
bool IsWin5family()
{
	static int ibIsWin5fam = 0;
	if (!ibIsWin5fam)
	{
		OSVERSIONINFOEXW osvi = {sizeof(osvi), 5, 0};
		DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
		ibIsWin5fam = VerifyVersionInfoW(&osvi, VER_MAJORVERSION, dwlConditionMask) ? 1 : -1;
	}
	return (ibIsWin5fam == 1);
}
Exemplo n.º 23
0
 BOOL
	 IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WORD wServicePackMajor)
 {
	 BOOL  bRet = FALSE;
	 DWORD retCode;
	 OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0,{ 0 }, 0, 0 };
	 DWORDLONG        const dwlConditionMask = VerSetConditionMask(
		                                         VerSetConditionMask(
			                                       VerSetConditionMask(
				                                       0,  VER_MAJORVERSION, VER_GREATER_EQUAL),
			                                     VER_MINORVERSION, VER_GREATER_EQUAL),
		                                       VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);

	 osvi.dwMajorVersion = wMajorVersion;
	 osvi.dwMinorVersion = wMinorVersion;
	 osvi.wServicePackMajor = wServicePackMajor;

	 bRet = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask);
	 retCode = GetLastError();
	 return bRet;
 }
Exemplo n.º 24
0
// Initialization code
void AFX_GLOBAL_DATA::Initialize()
{
	if (m_bInitialized)
	{
		return;
	}

	OSVERSIONINFOEX osvi = { sizeof(osvi), HIBYTE(_WIN32_WINNT_WIN7), LOBYTE(_WIN32_WINNT_WIN7) };

	// The condition mask specifies to test for the OS major/minor versions using greater than or equal.
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);

	bIsWindows7 = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);

	bIsRemoteSession = GetSystemMetrics(SM_REMOTESESSION);

	UpdateSysColors();
	UpdateFonts();
	OnSettingChange();
	EnableAccessibilitySupport();
}
Exemplo n.º 25
0
// Only 5.x family (Win2k, WinXP, Win 2003 server)
bool IsWin5family()
{
	static int ibIsWin5fam = 0;
	if (!ibIsWin5fam)
	{
		// Don't use IsWinVerEqual here - we need to compare only major version!
		OSVERSIONINFOEXW osvi = {sizeof(osvi), 5, 0};
		DWORDLONG const dwlConditionMask = VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
		ibIsWin5fam = VerifyVersionInfoW(&osvi, VER_MAJORVERSION, dwlConditionMask) ? 1 : -1;
	}
	return (ibIsWin5fam == 1);
}
Exemplo n.º 26
0
bool CheckLdrNotificationAvailable()
{
	static bool bLdrWasChecked = false;
	if (bLdrWasChecked)
		return gbLdrDllNotificationUsed;

	#ifndef _WIN32_WINNT_WIN8
	#define _WIN32_WINNT_WIN8 0x602
	#endif
	_ASSERTE(_WIN32_WINNT_WIN8==0x602);
	OSVERSIONINFOEXW osvi = {sizeof(osvi), HIBYTE(_WIN32_WINNT_WIN8), LOBYTE(_WIN32_WINNT_WIN8)};
	DWORDLONG const dwlConditionMask = VerSetConditionMask(VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION, VER_GREATER_EQUAL);
	BOOL isAllowed = VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);

	// LdrDllNotification работает так как нам надо начиная с Windows 8
	// В предыдущих версиях Windows нотификатор вызывается из LdrpFindOrMapDll
	// ДО того, как были обработаны импорты функцией LdrpProcessStaticImports (а точнее LdrpSnapThunk)

	if (isAllowed)
	{
		HMODULE hNtDll = GetModuleHandle(L"ntdll.dll");
		if (hNtDll)
		{
			LdrRegisterDllNotification = (LdrRegisterDllNotification_t)GetProcAddress(hNtDll, "LdrRegisterDllNotification");
			LdrUnregisterDllNotification = (LdrUnregisterDllNotification_t)GetProcAddress(hNtDll, "LdrUnregisterDllNotification");

			if (LdrRegisterDllNotification && LdrUnregisterDllNotification)
			{
				gnLdrDllNotificationState = LdrRegisterDllNotification(0, LdrDllNotification, NULL, &gpLdrDllNotificationCookie);
				gbLdrDllNotificationUsed = (gnLdrDllNotificationState == 0/*STATUS_SUCCESS*/);
			}
		}
	}

	bLdrWasChecked = true;

	return gbLdrDllNotificationUsed;
}
Exemplo n.º 27
0
/* Test if this is a Vista machine or higher */
int isVista(void)
{
	OSVERSIONINFOEX InfoStruct;
	DWORD Mask;
	DWORDLONG ConditionMask=0;

	// Init
	InfoStruct.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	InfoStruct.dwMajorVersion = 6; // Vista
	Mask = VER_MAJORVERSION;
	VerSetConditionMask(ConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);

	return VerifyVersionInfo(&InfoStruct, Mask, ConditionMask);
}
Exemplo n.º 28
0
int CUtils::CheckOS() {
  int iType = OS_UNSUPPORTED;

#ifdef ENABLE_DISPLAY_MODULE
  OSVERSIONINFOEX osvi;
  ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
  osvi.dwPlatformId = VER_PLATFORM_WIN32_NT;
  osvi.dwMajorVersion = 6; // Vista
  DWORDLONG condmask = VerSetConditionMask (VerSetConditionMask (0, VER_MAJORVERSION, VER_GREATER_EQUAL),
                       VER_PLATFORMID, VER_EQUAL);

  if (VerifyVersionInfo (&osvi, VER_MAJORVERSION | VER_PLATFORMID, condmask)) {
    iType = OS_VISTA_UPPER;
  } else {
    osvi.dwMajorVersion = 5; // XP/2000
    if (VerifyVersionInfo (&osvi, VER_MAJORVERSION | VER_PLATFORMID, condmask))
      iType = OS_XP;
  }
#endif

  return iType;
}
Exemplo n.º 29
0
BOOL GetVersionMetric(WINVER_METRIC metric)
{
    // NB: OSVERSIONINFOEX is not supported on very early platforms but
    //     those don't require such a "metric"
    OSVERSIONINFOEXW ovi = { 0 };
    ovi.dwOSVersionInfoSize = sizeof(ovi);

    ULONGLONG dwlConditionMask = 0;

    switch (metric)
    {
        case WINVER_METRIC::ANY:
            return TRUE;

        case WINVER_METRIC::SERVER:
            ovi.wProductType = VER_NT_WORKSTATION;
            dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);
            return VerifyVersionInfoW(&ovi, VER_PRODUCT_TYPE, dwlConditionMask) == FALSE;

        case WINVER_METRIC::WORKSTATION:
            ovi.wProductType = VER_NT_WORKSTATION;
            dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);
            return VerifyVersionInfoW(&ovi, VER_PRODUCT_TYPE, dwlConditionMask) != FALSE;

        case WINVER_METRIC::HOMESERVER:
            ovi.wSuiteMask = VER_SUITE_WH_SERVER;
            dwlConditionMask = VerSetConditionMask(dwlConditionMask, VER_SUITENAME, VER_EQUAL);
            return VerifyVersionInfoW(&ovi, VER_SUITENAME, dwlConditionMask) != FALSE;

        default:
            ASSERT(false);
            break;
    }

    return FALSE;
}
Exemplo n.º 30
0
// we don't need any runtime initialization; only use Win32 API!
void __cdecl WinMainCRTStartup(void) {
   // variable for ExitProcess
	UINT exitCode;

	// variables for Tokenize
	LPTSTR infName;

	// variables for GetFullPathName
	LPTSTR fullPath;
	LPTSTR filePart;

	// variables for lstrcpy, lstrcat
	DWORD len;
	LPTSTR fixCmd;	
	LPTSTR argList;

	// variables for ShellExecuteEx
	SHELLEXECUTEINFO shExec;

	// variables for Wow64DisableWow64FsRedirection
	PVOID OldWow64FsRedirectionValue;

	// variables for VerifyVersionInfo
	OSVERSIONINFOEX verInfo;

	// declare these functions as pointers to load dynamically
	PW64DW64FR Wow64DisableWow64FsRedirection;
	PW64RW64FR Wow64RevertWow64FsRedirection;

	// attempt to load functions and store pointer in variable
	Wow64DisableWow64FsRedirection = (PW64DW64FR) GetProcAddress(
			GetModuleHandle(TEXT("kernel32.dll")), 
			"Wow64DisableWow64FsRedirection");
	Wow64RevertWow64FsRedirection = (PW64RW64FR) GetProcAddress(
			GetModuleHandle(TEXT("kernel32.dll")), 
			"Wow64RevertWow64FsRedirection");	

	// get the command line buffer from the environment
	infName = Tokenize (GetCommandLine ());

	// standard prefix to run an installer. first argument is a tuple of
	// the library name and the entry point; there must be a comma
	// between them and no spaces. rest of the command is passed to that
	// entry point. DefaultInstall is the name of the section, 128 is
	// flags, and the .inf name must be specified using a path to avoid
	// having it search for files in default directories.
	fixCmd = TEXT("setupapi.dll,InstallHinfSection DefaultInstall 128 ");

	// get canonical path of the argument
	len = GetFullPathName (infName, 0, NULL, NULL);
	// file does not exist?
	if (len == 0) {
	  exitCode = 0xFE;
	  goto cleanupFullPath;
	}
	fullPath = (LPTSTR) HeapAlloc (GetProcessHeap (), 0, (len+1) * sizeof(TCHAR));
	GetFullPathName (infName, len, fullPath, &filePart);
	// only directory was specified
	if (*filePart == '\0') {
	  exitCode = 0xFD;
	  goto cleanupFullPath;
	}

	// put all portions together to a total command line. note that the
	// InstallHinfSection argument list is not a regular command line. there
	// are always three fields: Section (DefaultInstall), Flags (128) and
	// Path, which are separated with a space. No quotes should be put around
	// the path, nor is the short name really necessary (on Windows 7 64-bit
	// there may not be a short name version available).
	len = lstrlen (fixCmd) + lstrlen (fullPath);
	argList = (LPTSTR) HeapAlloc (GetProcessHeap (), 0, (len+1) * sizeof(TCHAR));
	lstrcpy (argList, fixCmd);
	lstrcat (argList, fullPath);
	//MessageBox(NULL, argList, TEXT("argList"), MB_ICONINFORMATION | MB_OK);

	ZeroFill (&shExec, sizeof(SHELLEXECUTEINFO));
	shExec.cbSize = sizeof(SHELLEXECUTEINFO);
	shExec.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT | SEE_MASK_DOENVSUBST;
	
	// <http://codefromthe70s.org/vistatutorial.aspx>
	// <http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/elevate-a-process-at-the-command-line-in-vista.aspx>
	ZeroFill (&verInfo, sizeof(OSVERSIONINFOEX));
	verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	verInfo.dwMajorVersion = 6; // Vista
	if (VerifyVersionInfo (&verInfo, VER_MAJORVERSION,
			VerSetConditionMask (0, VER_MAJORVERSION, VER_GREATER_EQUAL))) {
		shExec.lpVerb = TEXT("runas");
	}
	// instead of calling InstallHinfSection ourself, we need to execute
	// the external program so that the native version (32- or 64-bits)
	// is run. it is always in system32, even on Windows x64! (folder
	// redirection is deactivated, so we'll get the native version).
	shExec.lpFile = TEXT("%SystemRoot%\\system32\\rundll32.exe");
	shExec.lpParameters = argList;
	shExec.nShow = SW_SHOWDEFAULT;

	// only call the WoW64 functions if they are available on our system
	if(NULL != Wow64DisableWow64FsRedirection)
		Wow64DisableWow64FsRedirection (&OldWow64FsRedirectionValue);

	// launch process and "inherit" exit code
	ShellExecuteEx (&shExec);
	WaitForSingleObject (shExec.hProcess, INFINITE);
	GetExitCodeProcess (shExec.hProcess, &exitCode);
	CloseHandle (shExec.hProcess);
  
	if (NULL != Wow64RevertWow64FsRedirection)
		Wow64RevertWow64FsRedirection (OldWow64FsRedirectionValue);

	// not really necessary, but it's a habit hard to turn
	HeapFree (GetProcessHeap (), 0, argList);
 cleanupFullPath:
	HeapFree (GetProcessHeap (), 0, fullPath);
  
	ExitProcess (exitCode);
}