wrong value for osversion() on my system

Windows specific forum
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

wrong value for osversion() on my system

Post by sartic »

My system is Win 10 Pro 64bit

C:\Windows\System32>ver

Microsoft Windows [Version 10.0.10240]

osversion() detects my system as win 7 (value 80) but it should be 110
Using last pb 32bit version.
Same code works on other system.
What can I check?
I didn't mess anything with compatibility settings.
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
TassyJim
Enthusiast
Enthusiast
Posts: 151
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: wrong value for osversion() on my system

Post by TassyJim »

Windows 10 Pro 64bit
Microsoft Windows [Version 10.0.10586]
PB 5.41 32 bit
correctly give 110 (Windows 10)

I am sure that I tested it with W10 before the November update.
I have not had to run any compatibility settings changes for PB to run.

Jim
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: wrong value for osversion() on my system

Post by sartic »

Code: Select all

Procedure.l osversion_()
  detect_os.s="c:\programi\"
  version_os.l=0
  ver_lin.s=""
  If FileSize(detect_os)<>-2
    If CreateDirectory(detect_os)
      Delay(999)
    EndIf
  EndIf
  If RunProgram("cmd"," /c ver | findstr /b /c:"+Chr(34)+"Microsoft"+Chr(34)+" > "+detect_os+"$",detect_os,#PB_Program_Wait)
    If OpenFile(199,detect_os+"$")
      ver_lin=LCase(ReadString(199))   
      If FindString(ver_lin,"version 10")>0
        version_os=#PB_OS_Windows_10
      Else
        version_os=OSVersion()
      EndIf
      CloseFile(199)
    EndIf
  EndIf
  ProcedureReturn version_os
EndProcedure

Debug OSVersion_()
Debug OSVersion()
and result:

Code: Select all

110
80
__________________________________________________
Code tags added
03.01.2016
RSBasic
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
User avatar
gally
User
User
Posts: 37
Joined: Thu May 28, 2009 9:07 pm
Location: France
Contact:

Re: wrong value for osversion() on my system

Post by gally »

Code: Select all

#KEY_WOW64_64KEY                      = $100
#KEY_WOW64_32KEY                      = $200

Procedure.s ReadRegKey(OpenKey.i, SubKey.s, ValueName.s)
; ROUTINE DE LECTURE DE CLEF DE REGISTRES.
  Define iRes.i      = 0
  Define hKey.i      = 0
  Define DataSize.i  = 255
  Define KeyValue.s  = Space(DataSize)

  If Left(SubKey, 1) = "\"
    SubKey = Right(SubKey, Len(SubKey) - 1)
  EndIf
  If OSVersion() <= #PB_OS_Windows_2000
    iRes = RegOpenKeyEx_(OpenKey, SubKey, 0, #KEY_READ | #KEY_WOW64_32KEY, @hKey)
  Else
    iRes = RegOpenKeyEx_(OpenKey, SubKey, 0, #KEY_READ | #KEY_WOW64_64KEY, @hKey)
  EndIf
  If iRes
    KeyValue = #Null$
  Else
    If RegQueryValueEx_(hKey, ValueName, 0, 0, @KeyValue, @DataSize)
      KeyValue = #Null$
    Else
      KeyValue = Left(KeyValue, DataSize - 1)
    EndIf
    RegCloseKey_(hKey)
  EndIf
  ProcedureReturn KeyValue

EndProcedure

Define sCurrentVer.s = ReadRegKey(#HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion")
Define sCurrentBld.s = ReadRegKey(#HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild")

Debug sCurrentVer + "." + sCurrentBld
DontTalkToMe
Enthusiast
Enthusiast
Posts: 334
Joined: Mon Feb 04, 2013 5:28 pm

Re: wrong value for osversion() on my system

Post by DontTalkToMe »

This doesn't work anymore.
Already discussed many times on the forum, with workaround.
MS wrote: We have made some significant changes in how the GetVersion(Ex) APIs work in Windows 8.1 due to undesirable customer behaviors resulting from how the GetVersion(Ex) APIs have been used in the past.

In previous versions of Windows, calling the GetVersion(Ex) APIs would return the actual version of the operating system (OS), unless the process had been mitigated by an app compat shim to give it a different version. This was done on a provisional basis and was relatively incomplete in terms of the number of processes that Microsoft could reasonably shim in a release. Many applications fell through the cracks because they didn’t get shimmed due to poorly designed version checks.

The number one reason to do a version check is to show some message of OS supportability for the application. However due to the poor checks, the message would often show that the app needed to be run on XP or later, which of course the newest OS is. More often than not, the newest OS would run the application without any issues if not for these checks.
Manifestation

In Windows 8.1, the GetVersion(Ex) APIs have been deprecated. That means that while you can still call the APIs, if your app does not specifically target Windows 8.1, you will get Windows 8 versioning (6.2.0.0).
Recent Windows versions now often lies -> http://www.purebasic.fr/english/viewtop ... 66#p479066
or alter your requests on many occasions.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: wrong value for osversion() on my system

Post by RSBasic »

@DontTalkToMe
Thank you very much for the helpful information.
Image
Image
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: wrong value for osversion() on my system

Post by sartic »

sartic wrote:

Code: Select all

Procedure.l osversion_()
  detect_os.s="c:\programi\"
  version_os.l=0
  ver_lin.s=""
  If FileSize(detect_os)<>-2
    If CreateDirectory(detect_os)
      Delay(999)
    EndIf
  EndIf
  If RunProgram("cmd"," /c ver | findstr /b /c:"+Chr(34)+"Microsoft"+Chr(34)+" > "+detect_os+"$",detect_os,#PB_Program_Wait)
    If OpenFile(199,detect_os+"$")
      ver_lin=LCase(ReadString(199))   
      If FindString(ver_lin,"version 10")>0
        version_os=#PB_OS_Windows_10
      Else
        version_os=OSVersion()
      EndIf
      CloseFile(199)
    EndIf
  EndIf
  ProcedureReturn version_os
EndProcedure

Debug OSVersion_()
Debug OSVersion()
and result:

Code: Select all

110
80
__________________________________________________
Code tags added
03.01.2016
RSBasic
result is:
6.3.10240

i presume 6.3 is wrong
Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
sartic
Enthusiast
Enthusiast
Posts: 143
Joined: Thu Aug 26, 2010 8:26 am

Re: wrong value for osversion() on my system

Post by sartic »

Registered user of PB (on Linux Mint 21.1 & Win 10 64bit)
Post Reply