📄 dtwinver.cpp
字号:
}
case PROCESSOR_ARCHITECTURE_ARM:
{
lpVersionInformation->EmulatedProcessorType = ARM_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_SHX:
{
lpVersionInformation->EmulatedProcessorType = SHX_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_ALPHA:
{
lpVersionInformation->EmulatedProcessorType = ALPHA_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_ALPHA64:
{
lpVersionInformation->EmulatedProcessorType = ALPHA64_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_PPC:
{
lpVersionInformation->EmulatedProcessorType = PPC_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_IA64:
{
lpVersionInformation->EmulatedProcessorType = IA64_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_AMD64:
{
lpVersionInformation->EmulatedProcessorType = AMD64_PROCESSOR;
break;
}
case PROCESSOR_ARCHITECTURE_UNKNOWN: //Deliberate fallthrough
default:
{
lpVersionInformation->EmulatedProcessorType = UNKNOWN_PROCESSOR;
break;
}
}
}
#endif
#else //We must be runing on an emulated or real version of Win16 or DOS
lpVersionInformation->EmulatedProcessorType = IA32_PROCESSOR; //We can only be running x86-32 code from 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->EmulatedPlatform = 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->UnderlyingPlatform = Windows9x;
//Deterine the Win9x Service pack installed
if (IsWindows95SP1(lpVersionInformation))
lpVersionInformation->wUnderlyingServicePackMajor = 1;
else if (IsWindows95B(lpVersionInformation))
lpVersionInformation->wUnderlyingServicePackMajor = 2;
else if (IsWindows95C(lpVersionInformation))
{
lpVersionInformation->wUnderlyingServicePackMajor = 2;
lpVersionInformation->wUnderlyingServicePackMinor = 5;
}
else if (IsWindows98SP1(lpVersionInformation))
lpVersionInformation->wUnderlyingServicePackMajor = 1;
}
else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
lpVersionInformation->UnderlyingPlatform = WindowsNT;
//Determine the NT Service pack
lpVersionInformation->wEmulatedServicePackMajor = 0; //Win16 does not have a concept of a service pack
lpVersionInformation->wUnderlyingServicePackMajor = GetNTServicePackFromCSDString(osvi.szCSDVersion);
//Determine the OS Type
GetNTOSTypeFromRegistry(lpVersionInformation, FALSE);
#ifndef UNDER_CE
//Determine if it is NT SP6a Vs SP6
GetNTSP6aDetailsFromRegistry(lpVersionInformation, FALSE);
//Determine if it is XP SP1a Vs SP1
GetXPSP1aDetailsFromRegistry(lpVersionInformation, FALSE);
//Determine the HAL details
GetNTHALDetailsFromRegistry(lpVersionInformation);
#endif
//Get the Product Suites installed
GetProductSuiteDetailsFromRegistry(lpVersionInformation);
GetTerminalServicesRemoteAdminModeDetailsFromRegistry(lpVersionInformation);
GetMediaCenterDetails(lpVersionInformation);
GetTabletPCDetails(lpVersionInformation);
GetStarterEditionDetails(lpVersionInformation);
GetR2Details(lpVersionInformation);
GetProductInfo(lpVersionInformation);
}
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->UnderlyingPlatform = WindowsNT;
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
bFoundUnderlyingOS = TRUE;
}
}
//Get the processor details
GetProcessorType(lpVersionInformation);
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->UnderlyingPlatform = 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->EmulatedPlatform = Dos;
lpVersionInformation->dwEmulatedMajorVersion = (DWORD) DosMajor;
lpVersionInformation->dwEmulatedMinorVersion = (DWORD) DosMinor;
lpVersionInformation->dwEmulatedBuildNumber = 0; //no build number with DOS
//See can we get the underlying OS info by calling WriteVer
if (!GetInfoBySpawingWriteVer(lpVersionInformation))
{
//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, "");
//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->UnderlyingPlatform = WindowsNT;
}
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->UnderlyingPlatform = Windows9x;
else
{
//Could not find method of differentiating between WFW & Win3.1 under DOS,
//so assume Win3.1
lpVersionInformation->UnderlyingPlatform = Windows3x;
}
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
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 B [aka 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->UnderlyingPlatform = Dos;
_fstrcpy(lpVersionInformation->szUnderlyingCSDVersion, "");
}
}
}
#endif
#endif
return TRUE;
}
#ifndef _DOS
void COSVersion::GetNTSP6aDetailsFromRegistry(LPOS_VERSION_INFO lpVersionInformation, BOOL bUpdateEmulatedAlso)
{
#ifndef UNDER_CE
if ((lpVersionInformation->dwUnderlyingMajorVersion == 4) && (lpVersionInformation->wUnderlyingServicePackMajor == 6))
{
//Test for SP6 versus SP6a.
HKEY hKey;
#if (defined(_WIN32) || defined(_WIN64))
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
#else
if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), &hKey) == ERROR_SUCCESS)
#endif
{
lpVersionInformation->wUnderlyingServicePackMinor = 1;
if (bUpdateEmulatedAlso)
lpVersionInformation->wEmulatedServicePackMinor = 1;
}
RegCloseKey(hKey);
}
#endif
}
#endif
#ifndef _DOS
void COSVersion::GetXPSP1aDetailsFromRegistry(LPOS_VERSION_INFO lpVersionInformation, BOOL bUpdateEmulatedAlso)
{
#ifndef UNDER_CE
if ((lpVersionInformation->dwUnderlyingMajorVersion == 5) && (lpVersionInformation->dwUnderlyingMinorVersion != 0) && (lpVersionInformation->wUnderlyingServicePackMajor == 1))
{
//Test for SP1a versus SP1.
HKEY hKey;
#if (defined(_WIN32) || defined(_WIN64))
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
#else
if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), &hKey) == ERROR_SUCCESS)
#endif
{
TCHAR sTemp[1024];
DWORD dwBufLen = 1024 * sizeof(TCHAR);
#if (defined(_WIN32) || defined(_WIN64))
if (::RegQueryValueEx(hKey, _T("SubVersionNumber"), NULL, NULL, (LPBYTE) sTemp, &dwBufLen) == ERROR_SUCCESS)
#else
if (RegQueryValueEx(hKey, _T("SubVersionNumber"), NULL, NULL, (LPBYTE) sTemp, &dwBufLen) == ERROR_SUCCESS)
#endif
{
if (_tcsicmp(sTemp, _T("a")) == 0)
{
lpVersionInformation->wUnderlyingServicePackMinor = 1;
if (bUpdateEmulatedAlso)
lpVersionInformation->wEmulatedServicePackMinor = 1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -