📄 dtwinver.cpp
字号:
/*
Module : Dtwinver.cpp
Purpose: Implementation of a comprehensive class to perform OS version detection
Created: PJN / 11-05-1996
History: PJN / 24-02-1997 A number of updates including support for NT 3.1,
single mode dos in Windows 95 and better Windows
version detecion under real mode dos.
PJN / 13-09-1998 1. Added explicit support for Windows 98
2. Updated documentation to use HTML.
3. Minor update to the web page describing it.
PJN / 22-06-1999 1. UNICODE enabled the code.
2. Removed need for the dwOSVersionInfoSize variable
3. Added support for detecting Build Number of 95 and 98 from DOS code path.
4. Now ships as standard with VC 5 workspace files
5. Added explicit support for Windows 95 SP 1
6. Added explicit support for Windows 95 OSR 2
7. Added explicit support for Windows 98 Second Edition
8. Added explicit support for Windows 2000
9. Added explicit support for Windows CE
10. Added explicit support for Windows Terminal Server's
11. Added explicit support for NT Stand Alone Server's.
12. Added explicit support for NT Primary Domain Controller's
13. Added explicit support for NT Backup Domain Controller's
PJN / 23-07-1999 Tested out support for Windows 98 SE, minor changes required
PJN / 26-07-1999 Added explicit support for Windows 98 SP 1
PJN / 28-07-1999 1. Fixed a problem when application is build in non-huge/large
memory model in Win16
2. Added explicit support for returning NT and Win9x service pack information
from Win32 and Win16 code paths
3. Updated test program to not bother reporting on any info which does not
exist. e.g. if there is no service pack installed, then we don't bother
displaying any info about service packs
4. Added explicit support for NT Enterprise Edition
PJN / 30-06-2000 1. Added explicit support for Windows Millennium Edition
PJN / 29-01-2001 1. Added explicit support for Windows XP (Whistler) Personal
2. Added explicit support for Windows XP (Whistler) Professional
3. Added explicit support for Windows XP (Whistler) Server
4. Added explicit support for Windows XP (Whistler) Advanced Server
5. Added explicit support for Windows XP (Whistler) Datacenter
6. Added explicit support for Windows XP (Whistler) 64 bit (all flavours)
7. Made all the code into a C++ class called COSVersion
8. Rewrote all the generic thunk code to be easier to follow
9. Generic thunk code now uses CallProcEx32W
10. Added explicit support for BackOffice Small Business Edition
11. Added explicit support for Terminal Services
12. 16 bit code path now can determine ProductSuite and ProductType type
thro additional generic thunk code
13. Provided a 64 bit test binary and make batch file (make64.bat) for
those lucky enough to have an Itanium processor and a beta of 64 bit Windows XP (Whistler).
14. Provided a Embedded C++ workspace and X86 Release binary.
15. Updated copyright information
PJN / 10-02-2001 1. Updated function names etc following MS decision to call Whistler "Windows XP"
PJN / 10-10-2001 1. Added code to 32 bit code path to detect if we are being run under 64 bit Windows. Also
updated the sample app to distinguish between emulated 64 bit and underlying
64 bit.
2. Updated the sample app to call XP Server its proper name which will be "Windows.NET Server"
PJN / 13-12-2001 1. Major upgrade. Now 16 bit DOS path can return as much information as native Win32 code.
This is achieved by spawning off the Win32 utility WriteVer with a special command line option.
Please note that if you intend deploying dtwinver then you must now ship the writever.exe file
in addition to linking in the dtwinver code into your application. Also this utilty needs
to be in the path or current directory when the dtwinver code is executing. Thanks to Chaz Angell
for prompted me into finding a solution for this last major item missing in dtwinver.
PJN / 30-12-2002 1. Provided an update CE workspace to work correctly in eMbedded Visual C++ v3. All build configurations
for eVC 3 have also been provided.
2. Optimized the usage of _tcscat and _tcscpy in the test app which comes with Dtwinver.cpp
3. OEM Info string and Platform Type string is now returned for CE code path
4. Fixed display of minor version number for example Windows .NET is version number v5.20 but
should be shown as 5.2 to be consistent with what the native ver command displays
5. Provided a new CE workspace to work correctly in eMbedded Visual C++ v4. All build configurations
for eVC 4 have also been provided.
PJN / 08-10-2002 1. Now uses OSVERSIONINFOEX it possible in the Win32 or Win64 code paths. This provides for
more reliably detection of Windows XP Home Edition.
2. Renamed the functions which detect Windows .NET Server 2003. Also updated the test code which
prints out these names
3. Provided explicit support for Windows .NET Web Server
4. Fixed a bug in the display of the minor OS version number on Windows .NET Server.
5. Made the project for WriteVer a VC 5 project instead of VC 6 which it was up until now.
6. Reworked the internal function WhichNTProduct to use a constant input string parameter
7. Added explicit support for Windows NT / 2000 / XP Embedded
8. Added explicit support for detecting Terminal Services in remote admin mode
PJN / 10-10-2002 1. Fixed a problem where on Windows XP, the test program will include the text "(Standard Edition)"
2. Added two variables to the OS_VERSION_INFO structure to report the minor service pack number
3. Removed the OS_VERSION_INFO structure from the global namespace
4. Removed all static member variables from the class
5. Added a member variable to the OS_VERSION_INFO to return the various "suites" installed
6. reduced the number of calls to WriteVer to 1 when called from dos code path.
7. Completely reworked the internal WhichNTProduct method
8. General tidy up of the header file
9. Completely reworked the ValidateProductSuite method
10. Now only 1 call is made to WhichNTProduct throughout a single call to COSVersion::GetVersion
11. Now only 1 call is made to ValidateProductSuite throughout a single call to COSVersion::GetVersion
12. Fixed an unitialized variable problem in COSVersion::IsUnderlying64Bit
13. Changed "WhichNTProduct" method to "GetNTOSTypeFromRegistry"
14. Changed "ValidateProductSuite" method to "GetProductSuiteDetailsFromRegistry".
15. Now correctly reports on Terminal Services being in Remote Admin Mode on OS which do not
support calling GetVersionEx using an OSVERSIONINFOEX structure i.e any NT 4 install prior to SP6.
16. 16 bit Windows code path now reports as much NT information as the Win32 code path
17. Fixed a bug in COSVersion::GetInfoBySpawingWriteVer which was failing if it encountered
an empty CSD string. This was spotted on Windows .NET Server which since it is in beta still
(as of October 2002) does not have any service pack!.
PJN / 10-01-2003 1. Update to support MS deciding to change the name of their Whistler Server product. The product
will now be called "Windows Server 2003".
PJN / 30-01-2003 1. Added explicit support for detecting NT Service Pack 6a
PJN / 08-02-2003 1. Added explicit support for detecting Windows XP Service Pack 1a
2. Added support to determine the HAL on NT Kernels.
PJN / 12-02-2003 1. Fixed a compiler warning in GetNTServicePackFromRegistry which occurs when the code is compiled
with the Watcom compiler. Thanks to Christian Kaiser for reporting this.
PJN / 08-03-2003 1. Updated a comment in COSVersion::GetProductSuiteDetailsFromRegistry re NT Embedded.
2. A comment from John A. Vorchak: On NTe (NT Embedded) and XPE (XP Embedded), all of the versions
(of DTWinver) work just fine so long as the components to support them are included in the images,
which itself is kind of a crap shoot. I think that you would probably find that most images will
not support the DOS or Win16 versions however most will support the Win32. Many of the images that
folks build either do not include the DOS subsystem and some of them do not include Explorer, so it
really can't be said that all builds will support them however it is not difficult for a developer
to understand which version would work for them as they understand their target systems better than
anyone and at least one version would certainly work for almost all images.
As far as Win2k (Server Appliance Kit), I haven't done enough testing with that platform, nor do I
currently have any built images with the SAK to say positively or otherwise. More than likely you
would find no problems with the SAK images since they typically follow W2k much more than NTe or
XPE do.
Author: If you are writing for an embedded OS, then there is little use for DTWinver!!, since the
developer has very tight control over the runtime environment. Also if you do use DTWinver on an
embedded version of Windows, you will probably compile in the dtwinver code rather than ship the
sample binaries I include in the dtwinver download.
PJN / 09-04-2004 1. Removed a number of unreferrenced variable warnings when you compile the code on on VS.NET 2003.
Thanks to Edward Livingston for reporting these issues.
2. Now includes support for Windows XP Media Center Edition. Please note that if you want to do
specific version checking of what version of Media Center you have installed then you should use
my CVersionInfo classes at http://www.naughter.com/versioninfo.html in conjunction with the following
information which I culled from http://www.mvps.org/marksxp/MediaCenter/2004/version.php which
describes the various version numbers of ehshell.exe in \Windows\ehome to the corresponding versions
of XP Media Center Edition.
Windows XP Media Center Edition: 2002 5.1.2600.1106 First released version of Windows Media Center
5.1.2600.1142 Highest released build of Media Center 2002
(provided via Q815487)
Windows XP Media Center Edition: 2004 5.1.2600.1217 Release build of Windows Media Center 2004
(upgrade over previous MCE 2002 build).
5.1.2600.1321 December 2003 Hotfix for Media Center 2004 version
(provided via Q830786)
5.1.2600.2096 Media Center Version included with Windows XP
Service Pack 2 Release Candidate 1. This version can
be installed over a current MCE 2002 or 2004 using
the Windows XP Service Pack 2 installer. If you have
any build between 1322 and 2095 assume this to be
a beta version.
3. dtwinver now returns the processor architecture via a call to GetSystemInfo or GetNativeSystemInfo.
This is used to differentiate between 64 Bit Windows on Itanium and AMD64 processors.
4. Renamed the global preprocesor defines used by dtwinver to use more unique names
5. Added make files and binaries for AMD64 processors
PJN / 26-06-2005 1. INTEL_PROCESSOR enum is now more correctly know as IA32 which means x86 32 bit.
2. Fixed a bug where the OS_VERSION_INFO parameter was not be zero set in the function
COSVersion::GetVersion. Thanks to "Remio" for reporting this issue.
PJN / 29-06-2005 1. Added support for detecting if code is running on Tablet PC Edition of Windows.
2. Code now uses GetSystemMetrics call in preference to direct registry calls to detect Media Center
Edition of Windows.
3. Renamed the functions which differentiate between the different OEM Service Release versions of Windows
95. They are OSR 2[.1] = Win95B, OSR2.5 = Win95C. For the gory details please see the KB article at
http://support.microsoft.com/kb/q158238/
PJN / 22-07-2005 1. Now includes support for Windows Vista, formerly Windows codename "Longhorn"
PJN / 06-09-2005 1. Renamed some of the functions which detect Longhorn Server. Previously the functions were
incorrectly referring to Vista Server. Vista is the name of the Windows Client. As of yet, a product
name has not been picked for Longhorn Server.
2. Now includes support for Windows Server 2003 R2.
3. Now includes support for Windows XP Starter Edition and any future versions such as Windows Vista
Starter Edition.
PJN / 17-05-2006 1. Updated copyright details.
2. Updated documentation to use the same style as the web site.
3. Updated documentation on version numbers which XP Media Center can have.
4. Added support for Windows Server 2003, Computer Cluster Edition
5. Added support for Windows Storage Server 2003 R2
6. Added support for detecting if Windows is installed in a "Security Application" mode
7. Added support for detecting BackOffice components are installed
7. Provided Visual Studio 2005 solutions to build DtWinver with.
PJN / 21-09-2006 1. Included support for detecting all the different types of Vista SKU's, namely:
Windows Vista Starter Edition, Windows Vista Home Basic N, Windows Vista Home Basic,
Windows Vista Home Premium, Windows Vista Business N, Windows Vista Business,
Windows Vista Enterprise, and Windows Vista Ultimate.
2. Fixed a bug in the displaying of unknown versions of Windows in the sample app
PJN / 18-05-2007 1. Updated copyright details.
2. Updated code to refer to Windows Server 2008 which was formerly known as Windows Server codename "Longhorn"
PJN / 20-06-2007 1. Include support for detecting Windows Home Server. Thanks to Petr Stejskal for suggesting this update.
PJN / 14-06-2008 1. Updated copyright details
2. Code now compiles cleanly using Code Analysis (/analyze)
3. Added support for Vista Home Premium N
4. Added support for Vista Business N
5. Added support for Vista Enterprise N
6. Added support for Vista Ultimate N
7. Added support for Windows Core Server
8. Added support for Windows Hyper-V
9. Added support for Windows Essential Business Server Management Server
10. Added support for Windows Essential Business Server Messaging Server
11. Added support for Windows Essential Business Server Security Server
12. Added support for Windows Storage Server Enterprise Edition
13. Added support for Windows Storage Server Express Edition
14. Added support for Windows Storage Server Standard Edition
15. Added support for Windows Storage Server Workgroup Edition
16. Added support for Windows Cluster Server Edition
17. Added support for Windows Business Server Premium Edition
PJN / 15-12-2008 1. Added support for detecting Windows 7
Copyright (c) 1997 - 2008 by PJ Naughter (Web: www.naughter.com, Email: pjna@naughter.com)
All rights reserved.
Copyright / Usage Details:
You are allowed to include the source code in any product (commercial, shareware, freeware or otherwise)
when your product is released in binary form. You are allowed to modify the source code in any way you want
except you cannot modify the copyright details at the top of each module. If you want to distribute source
code with your application, then you are only allowed to distribute versions released by the author. This is
to maintain a single distribution point for the source code.
*/
///////////////////////////////// Includes //////////////////////////////////
#include <windows.h>
#if defined(_WIN32) || defined(_WIN64)
#include <tchar.h>
#else
#include <ctype.h>
#include <stdlib.h>
#include <shellapi.h>
#endif
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "Dtwinver.h"
///////////////////////////////// Local function / variables /////////////////
#ifndef VER_NT_WORKSTATION
#define VER_NT_WORKSTATION 0x0000001
#endif
#ifndef VER_NT_DOMAIN_CONTROLLER
#define VER_NT_DOMAIN_CONTROLLER 0x0000002
#endif
#ifndef VER_NT_SERVER
#define VER_NT_SERVER 0x0000003
#endif
#ifndef PROCESSOR_ARCHITECTURE_SHX
#define PROCESSOR_ARCHITECTURE_SHX 4
#endif
#ifndef PROCESSOR_ARCHITECTURE_ARM
#define PROCESSOR_ARCHITECTURE_ARM 5
#endif
#ifndef PROCESSOR_ARCHITECTURE_IA64
#define PROCESSOR_ARCHITECTURE_IA64 6
#endif
#ifndef PROCESSOR_ARCHITECTURE_ALPHA64
#define PROCESSOR_ARCHITECTURE_ALPHA64 7
#endif
#ifndef PROCESSOR_ARCHITECTURE_MSIL
#define PROCESSOR_ARCHITECTURE_MSIL 8
#endif
#ifndef PROCESSOR_ARCHITECTURE_AMD64
#define PROCESSOR_ARCHITECTURE_AMD64 9
#endif
#ifndef PROCESSOR_ARCHITECTURE_IA32_ON_WIN64
#define PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 10
#endif
#ifndef SM_TABLETPC
#define SM_TABLETPC 86
#endif
#ifndef SM_MEDIACENTER
#define SM_MEDIACENTER 87
#endif
#ifndef SM_STARTER
#define SM_STARTER 88
#endif
#ifndef SM_SERVERR2
#define SM_SERVERR2 89
#endif
#ifndef VER_SUITE_SMALLBUSINESS
#define VER_SUITE_SMALLBUSINESS 0x00000001
#endif
#ifndef VER_SUITE_ENTERPRISE
#define VER_SUITE_ENTERPRISE 0x00000002
#endif
#ifndef VER_SUITE_BACKOFFICE
#define VER_SUITE_BACKOFFICE 0x00000004
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -