⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtwinver.cpp

📁 一个用vc获取系统硬件信息的例子
💻 CPP
📖 第 1 页 / 共 3 页
字号:

BOOL COSVersion::IsWindowsXP(LPOS_VERSION_INFO lpVersionInformation)
{
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_NT &&
          lpVersionInformation->dwUnderlyingMajorVersion == 5 &&
          lpVersionInformation->dwUnderlyingMinorVersion != 0);
}

WORD COSVersion::GetNTServicePackFromCSDString(LPCTSTR pszCSDVersion)
{
  WORD wServicePack = 0;
  if (_tcslen(pszCSDVersion))
  {
    //Parse out the CSDVersion string
    int i=0;      
    while (pszCSDVersion[i] != _T('\0') && !_istdigit(pszCSDVersion[i]))
      i++;
    wServicePack = (WORD) (_ttoi(&pszCSDVersion[i]));
  }

  return wServicePack;
}

#if defined(_WINDOWS) && !defined(UNDER_CE)
WORD COSVersion::GetNTServicePackFromRegistry()
{
  //By default assume no service pack
  WORD wServicePack = 0;

  HKEY hCurrentVersion;
  if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
                 &hCurrentVersion) == ERROR_SUCCESS)
  {
    BYTE byData[128];
    DWORD dwType;
    DWORD dwSize = 128;
#if defined(_WIN32) || defined(_WIN64)
    if (::RegQueryValueEx(hCurrentVersion, _T("CSDVersion"), NULL, &dwType, byData, &dwSize) == ERROR_SUCCESS)
#else
    if (RegQueryValueEx(hCurrentVersion, _T("CSDVersion"), NULL, &dwType, byData, &dwSize) == ERROR_SUCCESS)    
#endif    
    {
      if (dwType == REG_SZ)
      {
        //Stored as a string on all other versions of NT
        wServicePack = GetNTServicePackFromCSDString((TCHAR*) byData);
      }
      else if (dwType == REG_DWORD)
      {
        //Handle the service pack number being stored as a DWORD which happens on NT 3.1
        wServicePack = HIBYTE((WORD) *((DWORD*) &byData));
      }
    }

    //Don't forget to close the registry key we were using      
    RegCloseKey(hCurrentVersion);
  }

  return wServicePack;
}

BOOL COSVersion::ValidateProductSuite(LPCTSTR lpszSuiteToValidate) 
{
  // Open the ProductOptions key.
  HKEY hKey = NULL;
  LONG lResult = RegOpenKey(HKEY_LOCAL_MACHINE, _T("System\\CurrentControlSet\\Control\\ProductOptions"), &hKey);
  if (lResult != ERROR_SUCCESS)
    return FALSE;

  // Determine required size of ProductSuite buffer.
  DWORD dwType = 0;
  DWORD dwSize = 0;                   
#if defined(_WIN32) || defined(_WIN64)  
  lResult = ::RegQueryValueEx(hKey, _T("ProductSuite"), NULL, &dwType, NULL, &dwSize);
#else
  lResult = RegQueryValueEx(hKey, _T("ProductSuite"), NULL, &dwType, NULL, &dwSize);
#endif  
  if (lResult != ERROR_SUCCESS || !dwSize)
  {
    RegCloseKey(hKey);
    return FALSE;
  }

  // Allocate buffer.
  LPTSTR lpszProductSuites = (LPTSTR) new BYTE[dwSize];

  // Retrieve array of product suite strings.
#if defined(_WIN32) || defined(_WIN64)    
  lResult = ::RegQueryValueEx(hKey, _T("ProductSuite"), NULL, &dwType, (LPBYTE) lpszProductSuites, &dwSize);
#else                                                                                                     
  lResult = RegQueryValueEx(hKey, _T("ProductSuite"), NULL, &dwType, (LPBYTE) lpszProductSuites, &dwSize);
#endif  
  if (lResult != ERROR_SUCCESS || dwType != REG_MULTI_SZ)
  {
    //Don't forget to free up the resource we used
    delete [] lpszProductSuites;
    RegCloseKey(hKey);

    return FALSE;
  }

  //All string comparisons will be sub string only and case insensitive
  LPTSTR lpszLocalSuite = new TCHAR[_tcslen(lpszSuiteToValidate)+1];
  _tcscpy(lpszLocalSuite, lpszSuiteToValidate);
  _tcsupr(lpszLocalSuite);

  // Search for suite name in array of strings.
  BOOL bValidated = FALSE;
  LPTSTR lpszSuite = lpszProductSuites;
  while (*lpszSuite) 
  {
    //Ensure the string is upper case
    _tcsupr(lpszSuite);

    //Does the suite match up with the current item?
    if (_tcsstr(lpszSuite, lpszLocalSuite)) 
    {
      bValidated = TRUE;
      break;
    }
    lpszSuite += (lstrlen(lpszSuite) + 1);
  }

  //Don't forget to free up the resource we used
  delete [] lpszLocalSuite;
  delete [] lpszProductSuites;
  RegCloseKey(hKey);

  return bValidated;
}
#else 
WORD COSVersion::GetNTServicePackFromRegistry()
{
  return 0;
}

BOOL COSVersion::ValidateProductSuite(LPCTSTR /*lpszSuiteToValidate*/) 
{
  return FALSE;
}
#endif //#if defined(_WINDOWS) && !defined(UNDER_CE)
             
#if defined(_WIN64) || defined(_WIN32)             
BOOL COSVersion::IsWindows30(LPOS_VERSION_INFO /*lpVersionInformation*/)
#else
BOOL COSVersion::IsWindows30(LPOS_VERSION_INFO lpVersionInformation)
#endif //#if defined(_WIN64) || defined(_Win32             
{
#ifdef _WIN64
  return FALSE;
#elif _WIN32
  return FALSE;
#else
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_WINDOWS3x &&
          lpVersionInformation->dwUnderlyingMinorVersion == 0);
#endif
}

#if defined(_WIN64) || defined(_WIN32)             
BOOL COSVersion::IsWindows31(LPOS_VERSION_INFO /*lpVersionInformation*/)
#else
BOOL COSVersion::IsWindows31(LPOS_VERSION_INFO lpVersionInformation)
#endif //#if defined(_WIN64) || defined(_Win32             
{
#ifdef _WIN64
  return FALSE;
#elif _WIN32
  return FALSE;
#else
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_WINDOWS3x &&
          lpVersionInformation->dwUnderlyingMinorVersion == 10);
#endif
}

#if defined(_WIN64) || defined(_WIN32)            
BOOL COSVersion::IsWindows311(LPOS_VERSION_INFO /*lpVersionInformation*/)
#else
BOOL COSVersion::IsWindows311(LPOS_VERSION_INFO lpVersionInformation)
#endif //#if defined(_WIN64) || defined(_Win32             
{
#ifdef _WIN64
  return FALSE;
#elif _WIN32
  return FALSE;
#else
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_WINDOWS3x &&
          lpVersionInformation->dwUnderlyingMinorVersion == 11);
#endif
}

#if defined(_WINDOWS) && (!defined(_WIN32) && !defined(_WIN64))  
BOOL COSVersion::IsWindowsForWorkgroups(LPOS_VERSION_INFO lpVersionInformation)
#else
BOOL COSVersion::IsWindowsForWorkgroups(LPOS_VERSION_INFO /*lpVersionInformation*/)
#endif //#if defined(_WINDOWS) && (defined(_WIN32) || defined(_WIN64))  
{
#if defined(_WINDOWS) && (!defined(_WIN32) && !defined(_WIN64))  
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_WINDOWS3x &&
          WFWLoaded());
#else
  return FALSE;          
#endif //#if defined(_WINDOWS) && (!defined(_WIN32) && !defined(_WIN64))  
}


#if defined(_WIN32)
BOOL COSVersion::IsWin32sInstalled(LPOS_VERSION_INFO lpVersionInformation)
#else
BOOL COSVersion::IsWin32sInstalled(LPOS_VERSION_INFO /*lpVersionInformation*/)
#endif //#if defined(_WIN64) || defined(_Win32             
{
#ifdef _WIN64
  return FALSE;
#elif _WIN32
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_WINDOWS3x);
#else
  return FALSE;
#endif
}

BOOL COSVersion::IsNTPreWin2k(LPOS_VERSION_INFO lpVersionInformation)
{
  return (lpVersionInformation->dwUnderlyingPlatformId == DT_PLATFORM_NT &&
          lpVersionInformation->dwUnderlyingMajorVersion <= 4);
}

BOOL COSVersion::IsNTPDC(LPOS_VERSION_INFO lpVersionInformation)
{                                                               
  TCHAR pszProductType[100];
  return (IsNTPreWin2k(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("LANMANNT")) == 0);
}

BOOL COSVersion::IsNTStandAloneServer(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsNTPreWin2k(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("SERVERNT")) == 0);
}

BOOL COSVersion::IsNTBDC(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsNTPreWin2k(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("LANSECNT")) == 0);
}

BOOL COSVersion::IsTerminalServicesInstalled(LPOS_VERSION_INFO /*lpVersionInformation*/)
{
  return ValidateProductSuite(_T("Terminal Server"));
}

BOOL COSVersion::ISSmallBusinessEditionInstalled(LPOS_VERSION_INFO /*lpVersionInformation*/)
{
  return ValidateProductSuite(_T("SBS"));
}

BOOL COSVersion::IsNTWorkstation(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsNTPreWin2k(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("WinNT")) == 0);
}

BOOL COSVersion::IsNTEnterpriseServer(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsNTPreWin2k(lpVersionInformation) &&
          ValidateProductSuite(_T("Enterprise")));
}

BOOL COSVersion::IsNTDatacenterServer(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsNTPreWin2k(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("Center")) == 0);
}

BOOL COSVersion::IsWin2000Professional(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindows2000(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("WinNT")) == 0);
}

BOOL COSVersion::IsWin2000Server(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindows2000(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("SERVERNT")) == 0);
}

BOOL COSVersion::IsWin2000AdvancedServer(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsWindows2000(lpVersionInformation) &&
          ValidateProductSuite(_T("Enterprise")));
}

BOOL COSVersion::IsWin2000DatacenterServer(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsWindows2000(lpVersionInformation) &&
          ValidateProductSuite(_T("Data")));
}

BOOL COSVersion::IsWin2000DomainController(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindows2000(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("LanmanNT")) == 0);
}

BOOL COSVersion::IsXPPersonal(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsWindowsXP(lpVersionInformation) &&
          ValidateProductSuite(_T("Personal")));
}

BOOL COSVersion::IsXPProfessional(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindowsXP(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("WinNT")) == 0);
}

BOOL COSVersion::IsXPServer(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindowsXP(lpVersionInformation) &&
          WhichNTProduct(pszProductType) &&
          _tcsicmp(pszProductType, _T("SERVERNT")) == 0);
}

BOOL COSVersion::IsXPAdvancedServer(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsWindowsXP(lpVersionInformation) &&
          ValidateProductSuite(_T("Enterprise")));
}

BOOL COSVersion::IsXPDatacenterServer(LPOS_VERSION_INFO lpVersionInformation)
{
  return (IsWindowsXP(lpVersionInformation) &&
          ValidateProductSuite(_T("Data")));
}

BOOL COSVersion::IsXPDomainController(LPOS_VERSION_INFO lpVersionInformation)
{
  TCHAR pszProductType[100];
  return (IsWindowsXP(lpVersionInformation) &&
           WhichNTProduct(pszProductType) &&
           _tcsicmp(pszProductType, _T("LanmanNT")) == 0);
}

BOOL COSVersion::Is64Bit(LPOS_VERSION_INFO /*lpVersionInformation*/)
{
#ifdef _WIN64
  return TRUE;
#else
  return FALSE;
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -