bug cWinVersion() [fixed in 20.04]
bug cWinVersion() [fixed in 20.04]
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-
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
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: bug cWinVersion()
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
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()
6
1
7601
2
Thank you.
1
7601
2
Thank you.
Saludos / Regards,
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: bug cWinVersion()
Moises,
Please try this:
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()
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.
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.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: bug cWinVersion()
The powers that be, international politics, global warming, the tobacco lobbies, usual issuesAntonio Linares wrote:why not ?
- 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]
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
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]
Sorry, it does not work properly.
For instance, Windows 10 is reported as Windows 8.
For instance, Windows 10 is reported as Windows 8.
Saludos / Regards,
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
Re: bug cWinVersion() [still not fixed in 20.02]
Requiring also a corresponding manifest!
- 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]
Moisés,
Como ha indicado Günther, es necesario usar un determinado fichero "manifest":
https://docs.microsoft.com/es-es/window ... indows-8-1
Como ha indicado Günther, es necesario usar un determinado fichero "manifest":
En concreto, Microsoft proporciona este como ejemplo:* 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.
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]
Antonio,
Last check for Windows 2000 must be:
So this function will work fine.
Last check for Windows 2000 must be:
Code: Select all
if( vi.dwMajorVersion == 5 && vi.dwMinorVersion == 0 )
hb_retc( "Windows 2000" );
Saludos / Regards,
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
- 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]
Moises,
Thank you!
Included in FWH 20.04
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