Page 1 of 2

bug cWinVersion() [fixed in 20.04]

Posted: Mon Dec 30, 2019 11:10 am
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-

Re: bug cWinVersion()

Posted: Mon Dec 30, 2019 11:25 am
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

Re: bug cWinVersion()

Posted: Mon Dec 30, 2019 12:40 pm
by MOISES
6
1
7601
2

Thank you.

Re: bug cWinVersion()

Posted: Tue Dec 31, 2019 9:50 am
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
 

Re: bug cWinVersion()

Posted: Tue Dec 31, 2019 10:22 am
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.

Re: bug cWinVersion()

Posted: Tue Dec 31, 2019 10:42 am
by Antonio Linares
thanks...

why not ? :-)

Re: bug cWinVersion()

Posted: Tue Dec 31, 2019 11:37 am
by AntoninoP
Antonio Linares wrote:why not ? :-)
The powers that be, international politics, global warming, the tobacco lobbies, usual issues :D

Re: bug cWinVersion()

Posted: Mon Mar 09, 2020 4:06 pm
by MOISES
Up!

Re: bug cWinVersion()

Posted: Tue Mar 31, 2020 9:41 am
by MOISES
Up!!

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

Posted: Tue Mar 31, 2020 10:46 am
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

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

Posted: Wed Apr 01, 2020 9:16 am
by MOISES
Sorry, it does not work properly.

For instance, Windows 10 is reported as Windows 8.

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

Posted: Wed Apr 01, 2020 9:46 am
by byte-one
Requiring also a corresponding manifest!

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

Posted: Wed Apr 01, 2020 12:25 pm
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>

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

Posted: Tue Apr 28, 2020 4:50 pm
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.

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

Posted: Wed Apr 29, 2020 1:17 am
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