Exemple #1
0
BOOL COSVersion::GetVersion(LPOS_VERSION_INFO lpVersionInformation)
{                
  //By Default assume no service pack is installed
  lpVersionInformation->wEmulatedServicePack = 0;
  lpVersionInformation->wUnderlyingServicePack = 0;

  #ifdef UNDER_CE
    OSVERSIONINFO osvi;
    memset(&osvi, 0, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    if (!GetVersionEx(&osvi))
      return FALSE;

    lpVersionInformation->dwEmulatedMajorVersion = osvi.dwMajorVersion; 
    lpVersionInformation->dwEmulatedMinorVersion = osvi.dwMinorVersion; 
    lpVersionInformation->dwEmulatedBuildNumber = LOWORD(osvi.dwBuildNumber); //ignore HIWORD
    _tcscpy(lpVersionInformation->szEmulatedCSDVersion, osvi.szCSDVersion);
    lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_WINDOWSCE;

    //underlying OS is the same
    lpVersionInformation->dwUnderlyingMajorVersion = lpVersionInformation->dwEmulatedMajorVersion; 
    lpVersionInformation->dwUnderlyingMinorVersion = lpVersionInformation->dwEmulatedMinorVersion; 
    lpVersionInformation->dwUnderlyingBuildNumber = lpVersionInformation->dwEmulatedBuildNumber;
    lpVersionInformation->dwUnderlyingPlatformId = lpVersionInformation->dwEmulatedPlatformId;
    _tcscpy(lpVersionInformation->szUnderlyingCSDVersion, lpVersionInformation->szEmulatedCSDVersion);
  #elif defined(_WIN32) || defined(_WIN64)
    //determine dynamically if GetVersionEx is available, if 
    //not then drop back to using GetVersion

    // Get Kernel handle
    HMODULE hKernel32 = GetModuleHandle(_T("KERNEL32.DLL"));
    if (hKernel32 == NULL)
      return FALSE;

    #ifdef _UNICODE
      lpfnGetVersionEx lpGetVersionEx = (lpfnGetVersionEx) GetProcAddress(hKernel32, "GetVersionExW");
    #else
      lpfnGetVersionEx lpGetVersionEx = (lpfnGetVersionEx) GetProcAddress(hKernel32, "GetVersionExA");
    #endif

    if (lpGetVersionEx)
    {
      OSVERSIONINFO osvi;
      memset(&osvi, 0, sizeof(OSVERSIONINFO));
      osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
      if (!lpGetVersionEx(&osvi))
        return FALSE;

      lpVersionInformation->dwEmulatedMajorVersion = osvi.dwMajorVersion; 
      lpVersionInformation->dwEmulatedMinorVersion = osvi.dwMinorVersion; 
      lpVersionInformation->dwEmulatedBuildNumber = LOWORD(osvi.dwBuildNumber); //ignore HIWORD
      _tcscpy(lpVersionInformation->szEmulatedCSDVersion, osvi.szCSDVersion);
    
      //Explicitely map the win32 dwPlatformId to our own values 
      //Also work out the various service packs which are installed
      if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
      {
        lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_WINDOWS9x;

        //Deterine the Win9x Service pack installed
        if (IsWindows95SP1(lpVersionInformation))
        {
          lpVersionInformation->wEmulatedServicePack = 1;
          lpVersionInformation->wUnderlyingServicePack = 1;
        }
        else if (IsWindows95OSR2(lpVersionInformation))
        {
          lpVersionInformation->wEmulatedServicePack = 2;
          lpVersionInformation->wUnderlyingServicePack = 2;
        }
        else if (IsWindows98SP1(lpVersionInformation))
        {
          lpVersionInformation->wEmulatedServicePack = 1;
          lpVersionInformation->wUnderlyingServicePack = 1;
        }
      }
      else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
      {
        lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_NT;

        //Determine the NT Service pack
        lpVersionInformation->wEmulatedServicePack = GetNTServicePackFromCSDString(osvi.szCSDVersion);
        lpVersionInformation->wUnderlyingServicePack = lpVersionInformation->wEmulatedServicePack;
      }
      else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_CE)
        lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_WINDOWSCE;

      if (osvi.dwPlatformId == VER_PLATFORM_WIN32s)  //32 bit app running on Windows 3.x
      {
        lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_WINDOWS9x;

        lpVersionInformation->dwUnderlyingMajorVersion = 3; 
        lpVersionInformation->dwUnderlyingMinorVersion = 10; 
        lpVersionInformation->dwUnderlyingBuildNumber = 0;
        lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_WINDOWS3x;
        _tcscpy(lpVersionInformation->szUnderlyingCSDVersion, _T(""));
      }
      else
      {
        lpVersionInformation->dwUnderlyingMajorVersion = lpVersionInformation->dwEmulatedMajorVersion; 
        lpVersionInformation->dwUnderlyingMinorVersion = lpVersionInformation->dwEmulatedMinorVersion; 
        lpVersionInformation->dwUnderlyingBuildNumber = lpVersionInformation->dwEmulatedBuildNumber;
        lpVersionInformation->dwUnderlyingPlatformId = lpVersionInformation->dwEmulatedPlatformId;
        _tcscpy(lpVersionInformation->szUnderlyingCSDVersion, lpVersionInformation->szEmulatedCSDVersion);
      }
    }
    else
    {
      //Since GetVersionEx is not available we need to fall back on plain
      //old GetVersion. Because GetVersionEx is available on all but v3.1 of NT
      //we can fill in some of the parameters ourselves.
      DWORD dwVersion = ::GetVersion();

      lpVersionInformation->dwEmulatedMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
      lpVersionInformation->dwEmulatedMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
      lpVersionInformation->dwEmulatedBuildNumber = 0;
      lpVersionInformation->dwEmulatedPlatformId   = DT_PLATFORM_NT;   
      lpVersionInformation->dwUnderlyingMajorVersion = lpVersionInformation->dwEmulatedMajorVersion;
      lpVersionInformation->dwUnderlyingMinorVersion = lpVersionInformation->dwEmulatedMinorVersion;
      lpVersionInformation->dwUnderlyingBuildNumber  = lpVersionInformation->dwEmulatedBuildNumber;
      lpVersionInformation->dwUnderlyingPlatformId   = lpVersionInformation->dwEmulatedPlatformId;   
      _tcscpy(lpVersionInformation->szUnderlyingCSDVersion, lpVersionInformation->szEmulatedCSDVersion);

      //Need to determine the NT Service pack by querying the registry directory.
      lpVersionInformation->wEmulatedServicePack = GetNTServicePackFromRegistry();
      lpVersionInformation->wUnderlyingServicePack = lpVersionInformation->wEmulatedServicePack;
    }
  #else //We must be runing on an emulated or real version of Win16 or DOS
    #ifdef _WINDOWS //Running on some version of Windows                   
      DWORD dwVersion = GetVersion();
      // GetVersion does not differentiate between Windows 3.1 and Windows 3.11
      
      lpVersionInformation->dwEmulatedMajorVersion = LOBYTE(LOWORD(dwVersion)); 
      lpVersionInformation->dwEmulatedMinorVersion = HIBYTE(LOWORD(dwVersion));
      lpVersionInformation->dwEmulatedBuildNumber  = 0; //no build number with Win3.1x
      lpVersionInformation->dwEmulatedPlatformId   = DT_PLATFORM_WINDOWS3x;
      
      //Call to get the underlying OS here through 16 -> 32 bit Generic Thunk
      BOOL bFoundUnderlyingOS = FALSE;
      OSVERSIONINFO osvi;                      
      memset(&osvi, 0, sizeof(OSVERSIONINFO));
      osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
      if (GetVersionEx(&osvi))
      {
        lpVersionInformation->dwUnderlyingMajorVersion = osvi.dwMajorVersion; 
        lpVersionInformation->dwUnderlyingMinorVersion = osvi.dwMinorVersion; 
        lpVersionInformation->dwUnderlyingBuildNumber = LOWORD(osvi.dwBuildNumber); //ignore HIWORD
        _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, osvi.szCSDVersion);
       
        //Explicitely map the win32 dwPlatformId to our own values
        if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
        {
          lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_WINDOWS9x;

          //Deterine the Win9x Service pack installed
          if (IsWindows95SP1(lpVersionInformation))
            lpVersionInformation->wUnderlyingServicePack = 1;
          else if (IsWindows95OSR2(lpVersionInformation))
            lpVersionInformation->wUnderlyingServicePack = 2;
          else if (IsWindows98SP1(lpVersionInformation))
            lpVersionInformation->wUnderlyingServicePack = 1;
        }
        else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
        {
          lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_NT;
  
          //Determine the NT Service pack
          lpVersionInformation->wUnderlyingServicePack = GetNTServicePackFromCSDString(osvi.szCSDVersion);
        }
        else
          return FALSE;
       
        bFoundUnderlyingOS = TRUE;
      }
      else
      {
        //We failed to get GetVersionEx so try to GetVersion instead. We known that we must be on
        //Windows NT 3.5 or earlier since anything released later by MS had this function.
        DWORD dwVersion = GetVersion();
        if (dwVersion)
        {              
          lpVersionInformation->dwUnderlyingMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
          lpVersionInformation->dwUnderlyingMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
          lpVersionInformation->dwUnderlyingBuildNumber  = 0;
          lpVersionInformation->dwUnderlyingPlatformId   = DT_PLATFORM_NT; 
          _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
   
          bFoundUnderlyingOS = TRUE;
        }
      }

      if (!bFoundUnderlyingOS)
      {
        //must be running on a real version of 16 bit Windows whose underlying OS is DOS
        lpVersionInformation->dwUnderlyingMajorVersion = HIBYTE(HIWORD(dwVersion)); 
        lpVersionInformation->dwUnderlyingMinorVersion = LOBYTE(HIWORD(dwVersion)); 
        lpVersionInformation->dwUnderlyingBuildNumber = 0; 
        lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_DOS;
        _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
      }
    #else //Must be some version of real or emulated DOS
      //Retreive the current version of emulated DOS
      BYTE DosMinor;
      BYTE DosMajor;
      _asm
      {
        mov ax, 3306h
        int 21h
        mov byte ptr [DosMajor], bl
        mov byte ptr [DosMinor], bh
      }
      lpVersionInformation->dwEmulatedPlatformId = DT_PLATFORM_DOS;
      lpVersionInformation->dwEmulatedMajorVersion = (DWORD) DosMajor; 
      lpVersionInformation->dwEmulatedMinorVersion = (DWORD) DosMinor;                
      lpVersionInformation->dwEmulatedBuildNumber = 0; //no build number with DOS

      //We can detect if NT is running as it reports DOS v5.5
      if ((lpVersionInformation->dwEmulatedMajorVersion == 5) &&
          (lpVersionInformation->dwEmulatedMinorVersion == 50))    //NT reports DOS v5.5
      {
        _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "Microsoft Windows NT");    
        //could not find method of determing version of NT from DOS,
        //so assume 3.50
        lpVersionInformation->dwUnderlyingMajorVersion = 3; 
        lpVersionInformation->dwUnderlyingMinorVersion = 50; 
        lpVersionInformation->dwUnderlyingBuildNumber = 0;  //cannot get access to build number from DOS
        lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_NT;
      }            
      else
      {
        //Get the underlying OS here via the int 2FH interface of Windows
        GetWinInfo();
        if (bRunningWindows)
        { 
          if (lpVersionInformation->dwEmulatedMajorVersion >= 7)  //Windows 9x marks itself as DOS 7 or DOS 8
            lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_WINDOWS9x;
          else                                                              
          {
            //Could not find method of differentiating between WFW & Win3.1 under DOS,
            //so assume Win3.1                                     
            lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_WINDOWS3x;      
          }  
          _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "Microsoft Windows");
          lpVersionInformation->dwUnderlyingMajorVersion = (WinVer & 0xFF00) >> 8; 
          lpVersionInformation->dwUnderlyingMinorVersion = WinVer & 0x00FF; 

          if (lpVersionInformation->dwEmulatedMajorVersion >= 8)  //Windows Me reports itself as DOS v8.0
            lpVersionInformation->dwUnderlyingBuildNumber = 3000; //This is the build number for Windows ME.
          else
          {
            if (lpVersionInformation->dwEmulatedMinorVersion == 0)
              lpVersionInformation->dwUnderlyingBuildNumber = 950; //Windows 95 Gold reports DOS v7.0                      
            else if (lpVersionInformation->dwUnderlyingMinorVersion > 0 && 
                     lpVersionInformation->dwUnderlyingMinorVersion < 3) 
            {                                                            
              //Testing for 95 SP1 has not been done, so the above check
              //may or may not work
              lpVersionInformation->dwUnderlyingBuildNumber = 1080; 
            }
            else if (lpVersionInformation->dwUnderlyingMinorVersion == 3)
              lpVersionInformation->dwUnderlyingBuildNumber = 1212; //Windows 95 OSR2 reports DOS 7.03 from 16 bit code
            else
              lpVersionInformation->dwUnderlyingBuildNumber = 1998; //Windows 98 or SE. There is no way to differentiate from real mode
                                                                    //between the two of them
          }
        }
        else //must be on a real version of DOS
        {                               
          lpVersionInformation->dwUnderlyingMajorVersion = (DWORD) DosMajor; 
          lpVersionInformation->dwUnderlyingMinorVersion = (DWORD) DosMinor;                
          lpVersionInformation->dwUnderlyingBuildNumber = 0; //no build number with DOS
          lpVersionInformation->dwUnderlyingPlatformId = DT_PLATFORM_DOS;
          _fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
        }
      }  
Exemple #2
0
CString GetOS()
{
	CString Response;
	OS_VERSION_INFO osvi;
	char sText[512]="";
	char sBuf[100]="";
	ZeroMemory(&osvi,sizeof(OS_VERSION_INFO));
	
	_stprintf(sText, _T("\nOperating System\n"));
	if (GetOSVersion(&osvi)) {                                           
//		_stprintf(sText, _T("Emulated OS: "));
		
		switch (osvi.dwEmulatedPlatformId) {
		case PLATFORM_DOS:               
			{
				_stprintf(sBuf, _T("Dos"));
				break;
			}
		case PLATFORM_WINDOWS31:         
			{
				_stprintf(sBuf, _T("Windows"));
				break;
			}
		case PLATFORM_WINDOWSFW:         
			{
				_stprintf(sBuf, _T("Windows For Workgroups"));
				break; 
			}
		case PLATFORM_WIN32S:
			{
				_stprintf(sBuf, _T("Win32s"));
				break; 
			}
		case PLATFORM_WINDOWS_CE:
			{
				_stprintf(sBuf, _T("Windows CE"));
				break;
			}
		case PLATFORM_WINDOWS:
			{
				if (IsWindows95(&osvi))
					_stprintf(sBuf, _T("Windows 95"));
				else if (IsWindows95SP1(&osvi))
					_stprintf(sBuf, _T("Windows 95 SP1"));
				else if (IsWindows95OSR2(&osvi))
					_stprintf(sBuf, _T("Windows 95 OSR2"));
				else if (IsWindows98(&osvi))
					_stprintf(sBuf, _T("Windows 98"));
				else if (IsWindows98SP1(&osvi))
					_stprintf(sBuf, _T("Windows 98 SP1"));
				else if (IsWindows98SE(&osvi))
					_stprintf(sBuf, _T("Windows 98 Second Edition"));
				else
					_stprintf(sBuf, _T("Windows ??"));
				break;
			}
		case PLATFORM_NT_WORKSTATION:
			{
				if (IsWindows2000(&osvi))
					_stprintf(sBuf, _T("Windows 2000 Professional"));
				else
					_stprintf(sBuf, _T("Windows NT Workstation"));
				break;
			}
		case PLATFORM_NT_PRIMARY_DOMAIN_CONTROLLER:         
			{
				if (IsWindows2000(&osvi))
					_stprintf(sBuf, _T("Windows 2000 Server (Acting as Primary Domain Controller)"));
				else
					_stprintf(sBuf, _T("Windows NT Server (Acting as Primary Domain Controller)"));
				break;
			}
		case PLATFORM_NT_BACKUP_DOMAIN_CONTROLLER:         
			{
				if (IsWindows2000(&osvi))
					_stprintf(sBuf, _T("Windows 2000 Server (Acting as Backup Domain Controller)"));
				else
					_stprintf(sBuf, _T("Windows NT Server (Acting as Backup Domain Controller)"));
				break;
			}
		case PLATFORM_NT_STAND_ALONE_SERVER:
			{
				if (IsWindows2000(&osvi))
					_stprintf(sBuf, _T("Windows 2000 Server (Acting as Standalone Sever)"));
				else
					_stprintf(sBuf, _T("Windows NT Server (Acting as Standalone Sever)"));
				break;
			}
		case PLATFORM_WINDOWS_TERMINAL_SERVER:
			{
				_stprintf(sBuf, _T("Windows NT Terminal Server"));
				break;
			}
		case PLATFORM_NT_ENTERPRISE_SERVER:
			{
				_stprintf(sBuf, _T("Windows NT Enterprise Edition"));
				break;
			}
		default: 
			{
				_stprintf(sBuf, _T("Unknown OS"));
				break;
			}
		}
	}                     
	_tcscat(sText, sBuf);
//	_stprintf(sBuf, _T(" v%d."), osvi.dwEmulatedMajorVersion);
//	_tcscat(sText, sBuf);     
//	_stprintf(sBuf, _T("%02d "), osvi.dwEmulatedMinorVersion);
//	_tcscat(sText, sBuf);                           
	if (osvi.wEmulatedServicePack)       
	{
		_stprintf(sBuf, _T(" Service Pack %d"), osvi.wEmulatedServicePack);
		_tcscat(sText, sBuf);
	}
	if (osvi.dwEmulatedBuildNumber)
	{
		_stprintf(sBuf, _T(" (Build %d)"), osvi.dwEmulatedBuildNumber);
		_tcscat(sText, sBuf);           
	}
	_tcscat(sText, _T(" \r\n"));
	;

	return sText;
}