//**************************************************************************** // $Module type: Package // $Module name: cOSVersionInfo // $Author : Wil van Antwerpen // Created : 2010-05-04 // License : LGPL // // Usage : In its most bare form you would call it to retrieve the string that // sums up all of the OS capabilities for your host like this: // // Function HostOS Returns String // Handle hoVersionInfo // String sOSVersion // // Move "" To sOSVersion // Get Create U_cOSVersionInfo To hoVersionInfo // If (hoVersionInfo) Begin // Get OSVersion Of hoVersionInfo To sOSVersion // End // // Function_Return sOSVersion // End_Function // HostOS // // Comment : This package is based on the regcheck package from http://www.vdf-guidance.com // The OS detection logic has been extracted from there and put in here. // It has been rewritten in a way that makes it more versatile and easier to use. // // The property peOSVersion should be used if you want to run code that depends // on a specific OS version. // // // Current Limitations, the code does not check for Hyper-V roles or // if windows is licensed, or if the Vista Version used is Ultimate or // Professional. For that we will need to use the GetProductInfo WinAPI // call. (Vista and up) Knowing the OS version is Vista is OK for now. // // *********************************************************************** Use Windows Use cOSVersionInfo.h use cWinKernEx.h // Package from the cWindowsEx project Use cSystemInfo.pkg Class cOSVersionInfo Is a cObject Procedure Construct_Object Forward Send Construct_Object // The next properties return info about the Operating System. // They are set by the procedure DoGetVersionInfo, which is send from // the automatically invoked DoCheckWindowsVersion. // // Identifies the major version number of the operating system. // For example, for Windows NT version 3.51, the major version number is 3; // and for Windows NT version 4.0, the major version number is 4. Property Integer piMajorVersion 0 // Identifies the minor version number of the operating system. For example, // for Windows NT version 3.51, the minor version number is 51; and for // Windows NT version 4.0, the minor version number is 0. // For Windows 95, dwMinorVersion is zero. // For Windows 98, dwMinorVersion is greater than zero. Property Integer piMinorVersion 0 // Identifies the build number of the operating system. Property Integer piBuildNumber 0 // Identifies the operating system platform. This member can be one of the // following values: // CP_VER_PLATFORM_WIN32s Win32s on Windows 3.1. // CP_VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95 or Windows 98. // CP_VER_PLATFORM_WIN32_NT Win32 on Windows NT. Property Integer piPlatFormId 0 // Windows NT: Contains a string, such as "Service Pack 3", // that indicates the latest Service Pack installed on the system. If no // Service Pack has been installed, the string is empty. // Windows 95: Contains a null-terminated string that provides arbitrary // additional information about the operating system. Property String psCSDVersion '' // PHvW 20/04/2002 14:37 // Identifies the major version number of the latest Service Pack installed // on the system. For example, for Service Pack 3, the major version // number is 3. If no Service Pack has been installed, the value is zero. Property Integer piServicePackMajor 0 // PHvW 20/04/2002 14:37 // Identifies the minor version number of the latest Service Pack installed // on the system. For example, for Service Pack 3, the minor version // number is 0. Property Integer piServicePackMinor 0 // PHvW 20/04/2002 14:37 // A set of bit flags that identify the product suites available on the system. // This member can be a combination of the following values. (see msdn) Property Integer piSuiteMask 0 // // The psSuite string only contains features which can be enabled or not, so it is NOT // a direct mapping to piSuiteMask. An example of this is if you are in a remote desktop // session or not. Property String psSuite "" // The Edition string contains specific details about the platform that cannot be // enabled as a role. So "Home" Edition or "Datacenter" edition are good examples. // R2 is a peOSVersion Property String psEdition "" // PHvW 20/04/2002 14:37 // Indicates additional information about the system. This member can be // one of the following values. VER_NT_WORKSTATION, VER_NT_SERVER, VER_NT_DOMAIN_CONTROLLER Property Integer piProductType 0 // PHvW 22/04/2002 17:48 // Contains which version of windows is running as a text. // If it can not sort it out it will be CS_OSVERSION_UNKNOWN (="Windows Version UNKNOWN") Property String psOSVersion CS_OSVERSION_UNKNOWN Property Integer peOSVersion CE_OSVERSION_UNKNOWN // PHvW 22/04/2002 17:50 // Running windows version is a server version Property Boolean pbNTServer False // PHvW 22/04/2002 17:50 // Running on a Windows HOME version. That is Windows ME and Windows XP Home // Both are not recommended platforms for business (networking is limited). // So not for vdf. Property Boolean pbWindowsHome False // pbX64 is set to true if your host OS is x64 Property Boolean pbX64 False // pbRemoteDesktop is set to true if your application currently runs under a remote desktop session Property Boolean pbRemoteDesktop False Property Boolean pbAdminRights False End_Procedure // Procedure sets OS info properties defined in this class Procedure DoGetVersionInfo Integer iRetval String sOSVersionInfo sCSDVersion Pointer pOSVersionInfo FillType _OSVERSIONINFO With 0 to sOSVersionInfo Put _OSVERSIONINFO_Size to sOSVersionInfo At _OSVERSIONINFO.dwOSVersionInfoSize GetAddress of sOSVersionInfo to pOSVersionInfo Move (GetVersionEx(pOSVersionInfo)) to iRetval Indicate Err False If not iRetval Begin Error 500 csOsVersionNumberCouldNotRetrieved Procedure_Return End GetBuff from sOSVersionInfo At _OSVERSIONINFO.dwMajorVersion to iRetval Set piMajorVersion to iRetval GetBuff from sOSVersionInfo At _OSVERSIONINFO.dwMinorVersion to iRetval Set piMinorVersion to iRetval GetBuff from sOSVersionInfo At _OSVERSIONINFO.dwPlatformID to iRetval Set piPlatFormId to iRetval GetBuff_String from sOSVersionInfo At _OSVERSIONINFO.szCSDVersion to sCSDVersion Move (Cstring(sCSDVersion)) to sCSDVersion Set psCSDVersion to (Trim(sCSDVersion)) End_Procedure Procedure DoGetVersionInfoEx Integer iRetval String sOSVersionInfoEx sCSDVersion Pointer pOSVersionInfoEx FillType _OSVERSIONINFOEX With 0 to sOSVersionInfoEX Put _OSVERSIONINFOEX_Size to sOSVersionInfoEx At _OSVERSIONINFOEX.dwOSVersionInfoSize GetAddress of sOSVersionInfoEX to pOSVersionInfoEX Move (GetVersionEx(pOSVersionInfoEx)) to iRetval Indicate Err False If not iRetval Begin Error 500 csOsVersionNumberCouldNotRetrieved Procedure_Return End GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.dwMajorVersion to iRetval Set piMajorVersion to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.dwMinorVersion to iRetval Set piMinorVersion to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.dwBuildNumber to iRetval Set piBuildNumber to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.dwPlatformID to iRetval Set piPlatFormId to iRetval GetBuff_String from sOSVersionInfoEx At _OSVERSIONINFOEX.szCSDVersion to sCSDVersion Move (Cstring(sCSDVersion)) to sCSDVersion Set psCSDVersion to (Trim(sCSDVersion)) GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.wServicePackMajor to iRetval Set piServicePackMajor to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.wServicePackMinor to iRetval Set piServicePackMinor to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.wSuiteMask to iRetval Set piSuiteMask to iRetval GetBuff from sOSVersionInfoEx At _OSVERSIONINFOEX.wProductType to iRetval Set piProductType to iRetval End_Procedure // // Determines processor architecture and windows editions // Procedure RetrieveOSEdition Integer iMajorVersion Integer iMinorVersion Integer iSuiteMask Handle hoSystemInfo Integer iProcessorArchitecture String sEdition Move PROCESSOR_ARCHITECTURE_UNKNOWN to iProcessorArchitecture // Min version is XP Get Create U_cSystemInfo to hoSystemInfo If (hoSystemInfo) Begin Get piProcessorArchitecture of hoSystemInfo to iProcessorArchitecture If (iProcessorArchitecture=PROCESSOR_ARCHITECTURE_AMD64) Begin Set pbX64 to True End End If (GetSystemMetrics(SM_MEDIACENTER)<>0) Begin Move CS_OS_MCE to sEdition End If (GetSystemMetrics(SM_STARTER)<>0) Begin Move CS_OS_STARTER to sEdition End If (GetSystemMetrics(SM_TABLETPC)<>0) Begin Move CS_OS_TABLETPC to sEdition End Case Begin Case (iSuiteMask iand Ver_Suite_Personal) Move CS_OS_HOME to sEdition Set pbWindowsHome to True Case Break Case (iSuiteMask iand Ver_Suite_EmbeddedNT) Move CS_OS_EMBEDDED to sEdition Case Break Case (iSuiteMask iand Ver_Suite_Blade) Move CS_OS_WEB to sEdition Case Break Case (iSuiteMask iand Ver_Suite_Datacenter) Move CS_OS_DATACENTER to sEdition Case Break Case (iSuiteMask iand Ver_Suite_Enterprise) Move CS_OS_ENTERPRISE to sEdition Case Break Case End If (sEdition <> "") Begin // Microsoft had the habit of adding "Edition" behind its edition identifier string in the past If (iMajorVersion = 5 and iMinorVersion >= 1) Move (sEdition * CS_OS_EDITION) to sEdition End Set psEdition to sEdition End_Procedure // // Determine the psSuite string and try to find out features such as if you are running in an // remote Desktop session, or if the user has administrator rights // Procedure RetrieveOSFeatures Integer iMajorVersion Integer iMinorVersion String sSuite Move "" to sSuite If (GetSystemMetrics(SM_REMOTESESSION) <> 0) Begin Move (sSuite + CS_OS_REMOTESESSION) to sSuite Set pbRemoteDesktop to True End If (iMajorVersion > 5 or (iMajorVersion >= 5 and iMinorVersion >= 1)) Begin // Check only win2000 and up If (IsAdministrator()) Begin If (sSuite <> "") Move (sSuite + ", ") to sSuite Move (sSuite + CS_OS_ISADMINISTRATOR) to sSuite Set pbAdminRights to True End End Set psSuite to sSuite End_Procedure // // This sets the psOsVersion and peOSVersion properties based on what has been found. // The psOSversion should not be used to identify the base OS, use peOSVersion for that. // Procedure RetrieveOSVersion Integer iMajorVersion Integer iMinorVersion Integer iBuildNumber Integer iPlatFormId String sCSDVersion String sOSVersion Integer iServicePackMajor Integer iServicePackMinor Integer iSuiteMask Integer iProductType Boolean bServerR2 Move False to bServerR2 Get piMajorVersion to iMajorVersion Get piMinorVersion to iMinorVersion Get piBuildNumber to iBuildNumber Get piPlatFormId to iPlatFormId Get psCSDVersion to sCSDVersion Get piServicePackMajor to iServicePackMajor Get piServicePackMinor to iServicePackMinor Get piSuiteMask to iSuiteMask Get piProductType to iProductType If (iMajorVersion > 5 or (iMajorVersion >= 5 and iMinorVersion >= 1)) Begin // Set psEdition and check x64 capabilities Send RetrieveOSEdition iMajorVersion iMinorVersion iSuiteMask If (GetSystemMetrics(SM_SERVERR2) <> 0) Begin Move True to bServerR2 End End If (iMajorVersion >= 5) Begin Send RetrieveOSFeatures iMajorVersion iMinorVersion End Case Begin Case (iMajorVersion = 3) Set psOSVersion to CS_OSVERSION_NT35 Set peOSVersion to CE_OSVERSION_NT35 Case Break Case (iMajorVersion = 4) // Windows 9X Series and Win NT 40 If (iPlatFormId = CP_VER_PLATFORM_WIN32_WINDOWS) Begin // Then Windows 95 or 98... Case Begin Case (iMinorVersion = 0) Set psOSVersion to CS_OSVERSION_WIN95 Set peOSVersion to CE_OSVERSION_WIN95 Case Break Case (iMinorVersion = 10) Set psOSVersion to CS_OSVERSION_WIN98 Set peOSVersion to CE_OSVERSION_WIN98 Case Break Case (iMinorVersion = 90) Set psOSVersion to CS_OSVERSION_WINME Set peOSVersion to CE_OSVERSION_WINME Set pbWindowsHome to True Case Break Case End End Else Begin Case Begin Case (iProductType = VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_NT4WKS Set peOSVersion to CE_OSVERSION_NT4WKS Case Break Case (iProductType = VER_NT_DOMAIN_CONTROLLER) Set psOSVersion to CS_OSVERSION_NT4SRV Set peOSVersion to CE_OSVERSION_NT4SRV Set pbNTServer to True Case Break Case End End Case Break Case (iMajorVersion = 5) // Windows NT2k Series Case Begin Case (iMinorVersion = 0) // Windows 2000 If (iProductType = VER_NT_WORKSTATION) Begin Set psOSVersion to CS_OSVERSION_W2K Set peOSVersion to CE_OSVERSION_W2K End Else Begin Set psOSVersion to CS_OSVERSION_W2KSRV Set peOSVersion to CE_OSVERSION_W2KSRV Set pbNTServer to True End Case Break Case (iMinorVersion = 1) // XP (and NOT 2003 server) Case Begin Case (iSuiteMask iand Ver_Suite_Personal) Set psOSVersion to CS_OSVERSION_WXP Set peOSVersion to CE_OSVERSION_WXP Set pbWindowsHome to True Case Break Case (iProductType = VER_NT_WORKSTATION) If (psEdition(Self)="") Move CS_OSVERSION_WXPPRO to sOSVersion Else Move CS_OSVERSION_WXP to sOSVersion Set psOSVersion to sOSVersion Set peOSVersion to CE_OSVERSION_WXP Case Break Case End Case Break Case (iMinorVersion = 2) Case Begin Case (iProductType = VER_NT_WORKSTATION and pbX64(Self)=True) Set psOSversion to CS_OSVERSION_WXPX64 Set peOSVersion to CE_OSVERSION_WXP Case Break Case (bServerR2 = False) Set psOSVersion to CS_OSVERSION_2K3 Set peOSVersion to CE_OSVERSION_2K3 Set pbNTServer to True Case Break Case (iSuiteMask iand VER_SUITE_WH_SERVER) Set psOSVersion to CS_OSVERSION_HMESRV Set peOSVersion to CE_OSVERSION_2K3 Set pbNTServer to True Case Break Case (bServerR2 = True) Set psOSVersion to CS_OSVERSION_2K3R2 Set peOSVersion to CE_OSVERSION_2K3R2 Set pbNTServer to True Case Break Case End Case Break Case End Case Break Case (iMajorVersion = 6) // Windows Vista & Windows 7 & Windows 8 Case Begin Case (iMinorVersion = 0) // Windows Vista Case Begin Case (iSuiteMask iand Ver_Suite_Personal) Set psOSVersion to CS_OSVERSION_VISTA Set peOSVersion to CE_OSVERSION_VISTA Set pbWindowsHome to True Case Break Case (iProductType = VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_VISTA Set peOSVersion to CE_OSVERSION_VISTA Case Break Case (iProductType <> VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_2K8 Set peOSVersion to CE_OSVERSION_2K8 Set pbNTServer to True Case Break Case End Case Break Case (iMinorVersion = 1) // Windows 7 Case Begin Case (iProductType = VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_W7 Set peOSVersion to CE_OSVERSION_W7 Case Break Case (iProductType <> VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_2K8R2 Set peOSVersion to CE_OSVERSION_2K8R2 Set pbNTServer to True Case Break Case End Case Break // *** Change 2012-07-23 NGS *** Additions for Windows 8 & 2012 Server Case (iMinorVersion = 2) Case Begin Case (iProductType = VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_WIN8 Set peOSVersion to CE_OSVERSION_W8 Case Break Case (iProductType <> VER_NT_WORKSTATION) Set psOSVersion to CS_OSVERSION_2K12 Set peOSVersion to CE_OSVERSION_W2K12SRV Set pbNTServer to True Case End Case Break Case End Case Break Case End End_Procedure // // Returns the full OS version name including service pack level as a string // // If the version is unknown to the package, it will list the major and // minor version appended the string returned in the format " (major.minor)" // Function OSVersion Returns String Integer iServicePack Integer iBuildNumber Integer iMajor Integer iMinor String sOSVersion String sSuite String sEdition String sCSDVersion Get psOSVersion to sOSVersion If (sOSVersion = CS_OSVERSION_UNKNOWN) Begin Get piMajorVersion to iMajor Get piMinorVersion to iMinor Move (sOSVersion +" (" + Trim(iMajor) + "." + Trim(iMinor) + ")") to sOSVersion End Else Begin Get psEdition to sEdition If (sEdition <> "") Begin Move (sOSVersion * sEdition) to sOSVersion End Get piBuildNumber to iBuildNumber If (iBuildNumber<>0) Begin Move (sOSVersion + " Build " + Trim(iBuildNumber) + " ") to sOSVersion End Get piServicePackMajor to iServicePack If (iServicePack > 0) Begin Get psCSDVersion to sCSDVersion Move (sOSVersion + sCSDVersion) to sOSVersion End End If (pbX64(Self)) Begin Move (sOSVersion * "x64") to sOSVersion End Get psSuite to sSuite If (sSuite <> "") Begin Move (sOSVersion * "(" + sSuite + ")") to sOSVersion End Function_Return sOSVersion End_Function // *** This is the MAIN PROCUDURE that checks which Windows version // is running and calls the appropiate procedure above. // SETS PUBLIC OS PROPERTIES // Gets called by End_Construct_Object below. Procedure DoCheckWindowsVersion Indicate Err False Send DoGetVersionInfo If ((piMajorVersion (Self)) > 4) Begin Indicate Err False Send DoGetVersionInfoEx End If not (Err) Begin Send RetrieveOSVersion End End_Procedure // Automatically sets all class properties upon creation. Procedure End_Construct_Object Forward Send End_Construct_Object Send DoCheckWindowsVersion End_Procedure End_Class