bug cWinVersion() [fixed in 20.04]

MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

bug cWinVersion() [fixed in 20.04]

Post by MOISES »

Hi,

cWinVersion() does not return the version of Windows 2008 server.

It does not detect it and returns incorrectly7 64 Bits - (6.1, Build 7601 Service Pack 1).

Thank you-
Last edited by MOISES on Tue Mar 31, 2020 9:42 am, edited 1 time in total.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion()

Post by Antonio Linares »

Moises,

Please run this code and let us know your results on Windows 2008 Server:

local a := GetVersion()

MsgInfo( a[ 1 ] )
MsgInfo( a[ 2 ] )
MsgInfo( a[ 3 ] )
MsgInfo( a[ 4 ] )

thank you
regards, saludos

Antonio Linares
www.fivetechsoft.com
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion()

Post by MOISES »

6
1
7601
2

Thank you.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion()

Post by Antonio Linares »

Moises,

Please try this:

Code: Select all

#define VER_PLATFORM_WIN32s         0
#define VER_PLATFORM_WIN32_WINDOWS  1
#define VER_PLATFORM_WIN32_NT       2

function cWinVersion()

   local aVersion := GetVersion()
   local cVersion := ""

   do case
      case aVersion[ 4 ] == VER_PLATFORM_WIN32_NT
           if aVersion[ 1 ] == 6
             if aVersion[ 2 ] == 0
                cVersion = "Vista"
             elseif aVersion[ 2 ] == 1
                 if aVersion[ 3 ] == 7601
                    cVersion = "Server 2008"
                 else                
                    cVersion = "7"
                 endif
             elseif aVersion[ 2 ] == 2
                if IsWindows10()
                   cVersion = "10"
                else
                   cVersion = "8"
                endif
             endif
           endif

           if aVersion[ 1 ] == 5
              if aVersion[ 2 ] == 2
                 cVersion = "Server 2003"
              elseif aVersion[ 2 ] == 1
                 cVersion = "XP"
              elseif aVersion[ 2 ] == 0
                 cVersion = "2000"
              endif
           endif

           if aVersion[ 1 ] <= 4
              cVersion = "NT"
           endif

      case aVersion[ 4 ] == VER_PLATFORM_WIN32_WINDOWS
           if aVersion[ 1 ] == 4
              if aVersion[ 2 ] == 90
                 cVersion = "ME"
              elseif aVersion[ 2 ] == 10
                 cVersion = "98"
              elseif aVersion[ 2 ] == 0
                 cVersion = "95"
              endif
           endif
   endcase

   cVersion += IF( IsWin64(), " 64 ", " 32 " ) + "Bits"

return cVersion
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: bug cWinVersion()

Post by AntoninoP »

Hello,
To distinguish between 7 and 2008 R2 (and between 10 and Server 2016, 8.1 and 2012 R2 etc etc..) you shoud use wProductType of OSVERSIONINFOEX.
We use a modified version cWinVersion based on the table present in https://docs.microsoft.com/en-us/window ... xa#remarks.
I'm not allowed to share that code.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion()

Post by Antonio Linares »

thanks...

why not ? :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: bug cWinVersion()

Post by AntoninoP »

Antonio Linares wrote:why not ? :-)
The powers that be, international politics, global warming, the tobacco lobbies, usual issues :D
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion()

Post by MOISES »

Up!
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion()

Post by MOISES »

Up!!
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion() [still not fixed in 20.02]

Post by Antonio Linares »

Moisés,

I have built this function following the MS table pointed by Antonino. In my Windows 10 it reports Windows 8...

I appreciate if you all test it on your PCs to check how it works

Code: Select all

// Detecting the Windows version

#include "FiveWin.ch"

function Main()

   MsgInfo( Windows() )

return nil

#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>

HB_FUNC( WINDOWS )
{
   OSVERSIONINFOEX vi;
   SYSTEM_INFO si;

   vi.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
   GetVersionEx( ( LPOSVERSIONINFO ) &vi );
   GetSystemInfo( &si );

   if( vi.dwMajorVersion == 10 && vi.dwMinorVersion == 0 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 10" );
      else
         hb_retc( "Windows Server 2016" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 3 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 8.1" );
      else
         hb_retc( "Windows Server 2012" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 2 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 8" );
      else
         hb_retc( "Windows Server 2012 R2" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 1 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 7" );
      else
         hb_retc( "Windows Server 2008 R2" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 0 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows Vista" );
      else
         hb_retc( "Windows Server 2008" );

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 2 )
      if( GetSystemMetrics( SM_SERVERR2 ) != 0 )
         hb_retc( "Windows Server 2003 R2" );
      else if( vi.wSuiteMask & VER_SUITE_WH_SERVER )
         hb_retc( "Windows Server 2003" );
      else if( vi.wProductType == VER_NT_WORKSTATION && 
              ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ) )
         hb_retc( "Windows XP Professional x64 Edition" );

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 1 )
      hb_retc( "Windows XP" );

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 1 )
      hb_retc( "Windows 2000" );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion() [still not fixed in 20.02]

Post by MOISES »

Sorry, it does not work properly.

For instance, Windows 10 is reported as Windows 8.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: bug cWinVersion() [still not fixed in 20.02]

Post by byte-one »

Requiring also a corresponding manifest!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion() [still not fixed in 20.02]

Post by Antonio Linares »

Moisés,

Como ha indicado Günther, es necesario usar un determinado fichero "manifest":
* For applications that have been manifested for Windows 8.1 or Windows 10. Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.
En concreto, Microsoft proporciona este como ejemplo:
https://docs.microsoft.com/es-es/window ... indows-8-1

Code: Select all

<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
    <assemblyIdentity
        type="win32"
        name="Contoso.ExampleApplication.ExampleBinary"
        version="1.2.3.4"
        processorArchitecture="x86"
    />
    <description>Contoso Example Application</description>
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
        <application>
            <!-- Windows 10 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> 
        </application>
    </compatibility>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
            <requestedPrivileges>
                <!--
                  UAC settings:
                  - app should run at same integrity level as calling process
                  - app does not need to manipulate windows belonging to
                    higher-integrity-level processes
                  -->
                <requestedExecutionLevel
                    level="asInvoker"
                    uiAccess="false"
                />   
            </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>
regards, saludos

Antonio Linares
www.fivetechsoft.com
MOISES
Posts: 824
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion() [still not fixed in 20.02]

Post by MOISES »

Antonio,

Last check for Windows 2000 must be:

Code: Select all

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 0 )
      hb_retc( "Windows 2000" );
So this function will work fine.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: bug cWinVersion() [still not fixed in 20.02]

Post by Antonio Linares »

Moises,

Thank you!

Included in FWH 20.04

Code: Select all

// Detecting the Windows version

#include "FiveWin.ch"

function Main()

   MsgInfo( Windows() )

return nil

#pragma BEGINDUMP

#include <Windows.h>
#include <hbapi.h>

HB_FUNC( WINDOWS )
{
   OSVERSIONINFOEX vi;
   SYSTEM_INFO si;

   vi.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
   GetVersionEx( ( LPOSVERSIONINFO ) &vi );
   GetSystemInfo( &si );

   if( vi.dwMajorVersion == 10 && vi.dwMinorVersion == 0 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 10" );
      else
         hb_retc( "Windows Server 2016" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 3 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 8.1" );
      else
         hb_retc( "Windows Server 2012" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 2 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 8" );
      else
         hb_retc( "Windows Server 2012 R2" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 1 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows 7" );
      else
         hb_retc( "Windows Server 2008 R2" );

   if( vi.dwMajorVersion == 6 && vi.dwMinorVersion == 0 )
      if( vi.wProductType == VER_NT_WORKSTATION )
         hb_retc( "Windows Vista" );
      else
         hb_retc( "Windows Server 2008" );

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 2 )
      if( GetSystemMetrics( SM_SERVERR2 ) != 0 )
         hb_retc( "Windows Server 2003 R2" );
      else if( vi.wSuiteMask & VER_SUITE_WH_SERVER )
         hb_retc( "Windows Server 2003" );
      else if( vi.wProductType == VER_NT_WORKSTATION &&
              ( si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ) )
         hb_retc( "Windows XP Professional x64 Edition" );

   if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 1 )
      hb_retc( "Windows XP" );

  if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 0 )
      hb_retc( "Windows 2000" );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply