Page 1 of 1

wrong value for osversion() on my system

Posted: Sat Jan 02, 2016 11:12 pm
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.

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 2:27 am
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

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 8:14 am
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

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 1:34 pm
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

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 2:26 pm
by RSBasic

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 2:50 pm
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.

Re: wrong value for osversion() on my system

Posted: Sun Jan 03, 2016 3:15 pm
by RSBasic
@DontTalkToMe
Thank you very much for the helpful information.

Re: wrong value for osversion() on my system

Posted: Mon Jan 04, 2016 5:40 pm
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

Re: wrong value for osversion() on my system

Posted: Mon Jan 04, 2016 5:42 pm
by sartic