* Program....: GETWINVER.PRG
* Version....: 1.0
* Author.....: ** Richard G Bean **
* Date.......: April 3, 2000
* Compiler...: Visual FoxPro 06.00.8492.00 for Windows
* ** RGB ** changed on 01/31/02 - Extended for XP+
* ** RGB ** changed on 10/06/05 - Extended for 2003, Vista
* ** RGB ** changed on 05/24/08 - Extended for 2008 and Product Type for v6.0 +
* ** RGB ** changed on 02/22/09 - Extended for Windows 7
* Based on MSDN KB Article Q188987
&& Don't currently use all these DEFINEs, but could if want to explore Server Versions
#DEFINE VER_PLATFORM_WIN32S 0
#DEFINE VER_PLATFORM_WIN32_WINDOWS 1
#DEFINE VER_PLATFORM_WIN32_NT 2
#DEFINE VER_SERVER_NT 0x80000000
#DEFINE VER_WORKSTATION_NT 0x40000000
#DEFINE VER_NT_WORKSTATION 0x00000001
#DEFINE VER_NT_DOMAIN_CONTROLLER 0x00000002
#DEFINE VER_NT_SERVER 0x00000003
#DEFINE VER_SUITE_SMALLBUSINESS 0x00000001
#DEFINE VER_SUITE_ENTERPRISE 0x00000002
#DEFINE VER_SUITE_BACKOFFICE 0x00000004
#DEFINE VER_SUITE_COMMUNICATIONS 0x00000008
#DEFINE VER_SUITE_TERMINAL 0x00000010
#DEFINE VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020
#DEFINE VER_SUITE_EMBEDDEDNT 0x00000040
#DEFINE VER_SUITE_DATACENTER 0x00000080
#DEFINE VER_SUITE_SINGLEUSERTS 0x00000100
#DEFINE VER_SUITE_PERSONAL 0x00000200
#DEFINE VER_SUITE_BLADE 0x00000400
#DEFINE FFFF 0x0000FFFF && 65535
Declare LONG GetVersionEx in WIN32API STRING
STORE INT(0) to;
dwOSVersionInfoSize,;
dwMajorVersion,;
dwMinorVersion,;
dwBuildNumber,;
dwPlatformId,;
wServicePackMajor,;
wServicePackMinor,;
wSuiteMask,;
wProductType,;
wReserved
szCSDVersion = ""
PId = "(Unknown)"
lcProduct = ''
lczStructure = chr(5*4+127+1+3*2+2*1)+replicate(chr(0), 5*4-1)+space(127)+chr(0);
+replicate(chr(0), 3*2+2*1)
lcReturn = ""
lnResult = GetVersionEx( @lczStructure )
IF lnResult <> 0 && No Error
dwOSVersionInfoSize = asc2BEint(lczStructure, 1, 4)
dwMajorVersion = asc2BEint(lczStructure, 5, 4)
dwMinorVersion = asc2BEint(lczStructure, 9, 4)
dwBuildNumber = BITAND(asc2BEint(lczStructure, 13, 4), FFFF)
dwPlatformId = asc2BEint(lczStructure, 17, 4)
szCSDVersion = ALLTRIM(CHRTRAN(SUBSTR(lczStructure, 21, 128),CHR(0)+CHR(1),""))
IF dwOSVersionInfoSize > 148
wServicePackMajor = asc2BEint(lczStructure, 149, 2)
wServicePackMinor = asc2BEint(lczStructure, 151, 2)
wSuiteMask = asc2BEint(lczStructure, 153, 2)
wProductType = ASC(SUBSTR(lczStructure, 155, 1))
wReserved = ASC(SUBSTR(lczStructure, 156, 1))
ENDIF
DO Case
Case dwPlatformId = VER_PLATFORM_WIN32S
PId = "32s " && "Windows 32s "
Case dwPlatformId = VER_PLATFORM_WIN32_WINDOWS
PId = "95/98 " && "Windows 95/98 "
DO CASE
CASE dwMajorVersion = 4 and dwMinorVersion = 0
PId = "95 " && "Windows 95 "
lcSubVer = SUBSTR(szCSDVersion, 1, 1)
IF INLIST(lcSubVer, "B", "C")
PId = PId + "OSR2 "
ENDIF
CASE dwMajorVersion = 4 and dwMinorVersion = 10
PId = "98 " && "Windows 98 "
lcSubVer = SUBSTR(szCSDVersion, 1, 1)
IF lcSubVer = "A"
PId = PId + "SE "
ENDIF
CASE dwMajorVersion = 4 and dwMinorVersion = 90
PId = "ME " && "Windows ME "
ENDCASE
Case dwPlatformId = VER_PLATFORM_WIN32_NT
PId = "NT " && "Windows NT "
DO CASE
CASE dwMajorVersion <= 4
PId = "NT " && "Windows NT "
CASE dwMajorVersion = 5
DO CASE
CASE dwMinorVersion = 0
PId = "2000 " && "Windows 2000 "
CASE dwMinorVersion = 1
PId = "XP " && "Windows XP "
IF BITAND(wSuiteMask, VER_SUITE_PERSONAL) <> 0
PId = PId + "Home "
ELSE
PId = PId + "Pro "
ENDIF
CASE dwMinorVersion = 2
PId = "2003 " && "Windows 2003 "
ENDCASE
CASE dwMajorVersion = 6
Declare INTEGER GetProductInfo in Kernel32 ;
LONG dwMajorVersion, ;
LONG dwMinorVersion, ;
LONG wServicePackMajor, ;
LONG wServicePackMinor, ;
LONG @pdwReturnedProductType
pdwReturnedProductType = INT(0)
lnResult = GetProductInfo( ;
dwMajorVersion, ;
dwMinorVersion, ;
wServicePackMajor, ;
wServicePackMinor, ;
@pdwReturnedProductType ;
)
IF lnResult = 1 && Good Result
lcProduct = getproduct(pdwReturnedProductType)
ENDIF
DO CASE
CASE dwMinorVersion = 0
IF BITAND(wProductType, VER_NT_SERVER) = VER_NT_SERVER
PId = "2008 " && "Windows 2008 Server "
ELSE
PId = "Vista " && "Windows Vista "
ENDIF
CASE dwMinorVersion = 1
PId = "Windows 7 " && "Windows 7 "
ENDCASE
ENDCASE
ENDCASE
lcReturn = PId ;
+ IIF(!EMPTY(lcProduct), lcProduct + ' ', '') ;
+ ALLTRIM(transform(dwMajorVersion,"@B 99999"));
+ "." + ALLTRIM(transform(dwMinorVersion,"@B 99999"));
+ "." + ALLTRIM(transform(dwBuildNumber,"@B 99999"));
+ " " + IIF(EMPTY(szCSDVersion),"(No SP)", szCSDVersion)
*c* + " (Build "+ ALLTRIM(transform(dwBuildNumber,"99999"));
*c* ;
*c* + ")"
*c* IF dwOSVersionInfoSize > 148
*c* lcReturn = lcReturn + CHR(13)+CHR(10)+TRANSFORM(wServicePackMajor) ;
*c* +" "+ TRANSFORM(wServicePackMinor) ;
*c* +" "+ TRANSFORM(wSuiteMask) ;
*c* +" "+ TRANSFORM(wProductType) ;
*c* +" "+ TRANSFORM(wReserved)
*c* ENDIF
ENDIF
RETURN lcReturn
**************************************************************************************
FUNCTION getproduct
LPARAMETERS znProductType
** pdwReturnedProductType
#DEFINE PRODUCT_BUSINESS 0x00000006 && Business Edition
#DEFINE PRODUCT_BUSINESS_N 0x00000010 && Business Edition
#DEFINE PRODUCT_CLUSTER_SERVER 0x00000012 && Cluster Server Edition
#DEFINE PRODUCT_DATACENTER_SERVER 0x00000008 && Server Datacenter Edition (full installation)
#DEFINE PRODUCT_DATACENTER_SERVER_CORE 0x0000000C && Server Datacenter Edition (core installation)
#DEFINE PRODUCT_DATACENTER_SERVER_CORE_V 0x00000027 && Server Datacenter Edition without Hyper-V (core installation)
#DEFINE PRODUCT_DATACENTER_SERVER_V 0x00000025 && Server Datacenter Edition without Hyper-V (full installation)
#DEFINE PRODUCT_ENTERPRISE 0x00000004 && Enterprise Edition
#DEFINE PRODUCT_ENTERPRISE_N 0x0000001B && Enterprise Edition
#DEFINE PRODUCT_ENTERPRISE_SERVER 0x0000000A && Server Enterprise Edition (full installation)
#DEFINE PRODUCT_ENTERPRISE_SERVER_CORE 0x0000000E && Server Enterprise Edition (core installation)
#DEFINE PRODUCT_ENTERPRISE_SERVER_CORE_V 0x00000029 && Server Enterprise Edition without Hyper-V (core installation)
#DEFINE PRODUCT_ENTERPRISE_SERVER_IA64 0x0000000F && Server Enterprise Edition for Itanium-based Systems
#DEFINE PRODUCT_ENTERPRISE_SERVER_V 0x00000026 && Server Enterprise Edition without Hyper-V (full installation)
#DEFINE PRODUCT_HOME_BASIC 0x00000002 && Home Basic Edition
#DEFINE PRODUCT_HOME_BASIC_N 0x00000005 && Home Basic Edition
#DEFINE PRODUCT_HOME_PREMIUM 0x00000003 && Home Premium Edition
#DEFINE PRODUCT_HOME_PREMIUM_N 0x0000001A && Home Premium Edition
#DEFINE PRODUCT_HOME_SERVER 0x00000013 && Home Server Edition
#DEFINE PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT 0x0000001E && Windows Essential Business Server Management Server
#DEFINE PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING 0x00000020 && Windows Essential Business Server Messaging Server
#DEFINE PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY 0x0000001F && Windows Essential Business Server Security Server
#DEFINE PRODUCT_SERVER_FOR_SMALLBUSINESS 0x00000018 && Server for Small Business Edition
#DEFINE PRODUCT_SMALLBUSINESS_SERVER 0x00000009 && Small Business Server
#DEFINE PRODUCT_SMALLBUSINESS_SERVER_PREMIUM 0x00000019 && Small Business Server Premium Edition
#DEFINE PRODUCT_STANDARD_SERVER 0x00000007 && Server Standard Edition (full installation)
#DEFINE PRODUCT_STANDARD_SERVER_CORE 0x0000000D && Server Standard Edition (core installation)
#DEFINE PRODUCT_STANDARD_SERVER_CORE_V 0x00000028 && Server Standard Edition without Hyper-V (core installation)
#DEFINE PRODUCT_STANDARD_SERVER_V 0x00000024 && Server Standard Edition without Hyper-V (full installation)
#DEFINE PRODUCT_STARTER 0x0000000B && Starter Edition
#DEFINE PRODUCT_STORAGE_ENTERPRISE_SERVER 0x00000017 && Storage Server Enterprise Edition
#DEFINE PRODUCT_STORAGE_EXPRESS_SERVER 0x00000014 && Storage Server Express Edition
#DEFINE PRODUCT_STORAGE_STANDARD_SERVER 0x00000015 && Storage Server Standard Edition
#DEFINE PRODUCT_STORAGE_WORKGROUP_SERVER 0x00000016 && Storage Server Workgroup Edition
#DEFINE PRODUCT_UNDEFINED 0x00000000 && An unknown product
#DEFINE PRODUCT_ULTIMATE 0x00000001 && Ultimate Edition
#DEFINE PRODUCT_ULTIMATE_N 0x0000001C && Ultimate Edition
#DEFINE PRODUCT_WEB_SERVER 0x00000011 && Web Server Edition (full installation)
#DEFINE PRODUCT_WEB_SERVER_CORE 0x0000001D && Web Server Edition (core installation)
LOCAL lcProductType
lcProductType = ''
DO CASE
** First the non-Servers
CASE znProductType = PRODUCT_BUSINESS OR znProductType = PRODUCT_BUSINESS_N
lcProductType = 'Business' && Edition'
CASE znProductType = PRODUCT_ENTERPRISE OR znProductType = PRODUCT_ENTERPRISE_N
lcProductType = 'Enterprise' && Edition'
CASE znProductType = PRODUCT_HOME_BASIC OR znProductType = PRODUCT_HOME_BASIC_N
lcProductType = 'Home Basic' && Edition'
CASE znProductType = PRODUCT_HOME_PREMIUM OR znProductType = PRODUCT_HOME_PREMIUM_N
lcProductType = 'Home Premium' && Edition'
CASE znProductType = PRODUCT_ULTIMATE OR znProductType = PRODUCT_ULTIMATE_N
lcProductType = 'Ultimate' && Edition'
CASE znProductType = PRODUCT_STARTER
lcProductType = 'Starter' && Edition'
CASE znProductType = PRODUCT_UNDEFINED
lcProductType = 'Unknown Product Type'
** Now the Servers
CASE znProductType = PRODUCT_CLUSTER_SERVER
lcProductType = 'Cluster Server Edition'
CASE znProductType = PRODUCT_DATACENTER_SERVER
lcProductType = 'Server Datacenter Edition (full installation)'
CASE znProductType = PRODUCT_DATACENTER_SERVER_CORE
lcProductType = 'Server Datacenter Edition (core installation)'
CASE znProductType = PRODUCT_DATACENTER_SERVER_CORE_V
lcProductType = 'Server Datacenter Edition without Hyper-V (core installation)'
CASE znProductType = PRODUCT_DATACENTER_SERVER_V
lcProductType = 'Server Datacenter Edition without Hyper-V (full installation)'
CASE znProductType = PRODUCT_ENTERPRISE_SERVER
lcProductType = 'Server Enterprise Edition (full installation)'
CASE znProductType = PRODUCT_ENTERPRISE_SERVER_CORE
lcProductType = 'Server Enterprise Edition (core installation)'
CASE znProductType = PRODUCT_ENTERPRISE_SERVER_CORE_V
lcProductType = 'Server Enterprise Edition without Hyper-V (core installation)'
CASE znProductType = PRODUCT_ENTERPRISE_SERVER_IA64
lcProductType = 'Server Enterprise Edition for Itanium-based Systems'
CASE znProductType = PRODUCT_ENTERPRISE_SERVER_V
lcProductType = 'Server Enterprise Edition without Hyper-V (full installation)'
CASE znProductType = PRODUCT_HOME_SERVER
lcProductType = 'Home Server Edition'
CASE znProductType = PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT
lcProductType = 'Windows Essential Business Server Management Server'
CASE znProductType = PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING
lcProductType = 'Windows Essential Business Server Messaging Server'
CASE znProductType = PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY
lcProductType = 'Windows Essential Business Server Security Server'
CASE znProductType = PRODUCT_SERVER_FOR_SMALLBUSINESS
lcProductType = 'Server for Small Business Edition'
CASE znProductType = PRODUCT_SMALLBUSINESS_SERVER
lcProductType = 'Small Business Server'
CASE znProductType = PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
lcProductType = 'Small Business Server Premium Edition'
CASE znProductType = PRODUCT_STANDARD_SERVER
lcProductType = 'Server Standard Edition (full installation)'
CASE znProductType = PRODUCT_STANDARD_SERVER_CORE
lcProductType = 'Server Standard Edition (core installation)'
CASE znProductType = PRODUCT_STANDARD_SERVER_CORE_V
lcProductType = 'Server Standard Edition without Hyper-V (core installation)'
CASE znProductType = PRODUCT_STANDARD_SERVER_V
lcProductType = 'Server Standard Edition without Hyper-V (full installation)'
CASE znProductType = PRODUCT_STORAGE_ENTERPRISE_SERVER
lcProductType = 'Storage Server Enterprise Edition'
CASE znProductType = PRODUCT_STORAGE_EXPRESS_SERVER
lcProductType = 'Storage Server Express Edition'
CASE znProductType = PRODUCT_STORAGE_STANDARD_SERVER
lcProductType = 'Storage Server Standard Edition'
CASE znProductType = PRODUCT_STORAGE_WORKGROUP_SERVER
lcProductType = 'Storage Server Workgroup Edition'
CASE znProductType = PRODUCT_WEB_SERVER
lcProductType = 'Web Server Edition (full installation)'
CASE znProductType = PRODUCT_WEB_SERVER_CORE
lcProductType = 'Web Server Edition (core installation)'
OTHERWISE
lcProductType = ''
ENDCASE
RETURN lcProductType
ENDFUNC
*!* EOP: GETWINVER.PRG
*FUNCTION asc2BEint && remove * if not in a separate .PRG file
* Abstract...: Ascii String to BigEndian Integer (i.e. Most significant byte on right)
* (use asc2int() for LittleEndian)
* Doesn't return negative numbers, Unless asked for
* RETURN -1 if any error
* Changes....:
*FUNCTION asc2BEint
LPARAMETERS p_cString, p_nStart, p_nLength, p_nAllowNegative
IF PCOUNT() < 1 OR VARTYPE(p_cString) <> "C"
RETURN -1
ENDIF
IF PCOUNT() < 2 OR VARTYPE(p_nStart) <> "N"
p_nStart = 1
ENDIF
IF PCOUNT() < 3 OR VARTYPE(p_nLength) <> "N"
p_nLength = LEN(p_cString)
ENDIF
IF PCOUNT() < 4 OR VARTYPE(p_nAllowNegative) <> "L"
p_nAllowNegative = .F.
ENDIF
LOCAL lnRet_val, llIsNegative, lcFixString, lnii, lcConvertString
lnRet_val = -1
llIsNegative = .F.
IF !BETWEEN(p_nLength, 1, 4)
RETURN lnRet_val
ENDIF
lcConvertString = SUBSTR(p_cString, p_nStart, p_nLength)
IF p_nAllowNegative
IF asc(SUBSTR(lcConvertString, (p_nLength-1), 1)) > 0x7F && It's Negative
lcFixString = lcConvertString
lcConvertString = ''
FOR lnii = 1 TO p_nLength
lcConvertString = lcConvertString + CHR(255-ASC(SUBSTR(lcFixString, lnii, 1))) && kludgy XOR
ENDFOR
llIsNegative = .T.
ENDIF
ENDIF
DO CASE
CASE p_nLength = 1
lnRet_val = asc(SUBSTR(lcConvertString, 1, 1))
CASE p_nLength = 2
lnRet_val = asc(SUBSTR(lcConvertString, 1, 1));
+ asc(SUBSTR(lcConvertString, 2, 1))*256
CASE p_nLength = 3
lnRet_val = asc(SUBSTR(lcConvertString, 1, 1));
+ asc(SUBSTR(lcConvertString, 2, 1))*256;
+ asc(SUBSTR(lcConvertString, 3, 1))*256^2
CASE p_nLength = 4
lnRet_val = asc(SUBSTR(lcConvertString, 1, 1));
+ asc(SUBSTR(lcConvertString, 2, 1))*256;
+ asc(SUBSTR(lcConvertString, 3, 1))*256^2;
+ asc(SUBSTR(lcConvertString, 4, 1))*256^3
OTHERWISE
lnRet_val = -1
ENDCASE
IF llIsNegative && Two's Complement Adj
lnRet_Val = -(lnRet_Val + 1)
ENDIF
RETURN INT(lnRet_val)
*!* EOP: ASC2BEINT.PRG