bug cWinVersion() [fixed in 20.04]

bug cWinVersion() [fixed in 20.04]

Postby MOISES » Mon Dec 30, 2019 11:10 am

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
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: bug cWinVersion()

Postby Antonio Linares » Mon Dec 30, 2019 11:25 am

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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bug cWinVersion()

Postby MOISES » Mon Dec 30, 2019 12:40 pm

6
1
7601
2

Thank you.
Saludos / Regards,

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

Re: bug cWinVersion()

Postby Antonio Linares » Tue Dec 31, 2019 9:50 am

Moises,

Please try this:

Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bug cWinVersion()

Postby AntoninoP » Tue Dec 31, 2019 10:22 am

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/windows/win32/api/winnt/ns-winnt-osversioninfoexa#remarks.
I'm not allowed to share that code.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: bug cWinVersion()

Postby Antonio Linares » Tue Dec 31, 2019 10:42 am

thanks...

why not ? :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: bug cWinVersion()

Postby AntoninoP » Tue Dec 31, 2019 11:37 am

Antonio Linares wrote:why not ? :-)

The powers that be, international politics, global warming, the tobacco lobbies, usual issues :D
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: bug cWinVersion()

Postby MOISES » Mon Mar 09, 2020 4:06 pm

Up!
Saludos / Regards,

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

Re: bug cWinVersion()

Postby MOISES » Tue Mar 31, 2020 9:41 am

Up!!
Saludos / Regards,

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

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

Postby Antonio Linares » Tue Mar 31, 2020 10:46 am

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  Expand view  RUN
// 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby MOISES » Wed Apr 01, 2020 9:16 am

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
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

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

Postby byte-one » Wed Apr 01, 2020 9:46 am

Requiring also a corresponding manifest!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

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

Postby Antonio Linares » Wed Apr 01, 2020 12:25 pm

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/windows/win32/sysinfo/targeting-your-application-at-windows-8-1

Code: Select all  Expand view  RUN
<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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby MOISES » Tue Apr 28, 2020 4:50 pm

Antonio,

Last check for Windows 2000 must be:

Code: Select all  Expand view  RUN
  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
MOISES
 
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

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

Postby Antonio Linares » Wed Apr 29, 2020 1:17 am

Moises,

Thank you!

Included in FWH 20.04

Code: Select all  Expand view  RUN
// 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 68 guests