Author Topic: OS Info for Windows 8 and 10  (Read 21012 times)

sinsi

  • Member
  • *****
  • Posts: 1040
Re: OS Info for Windows 8 and 10
« Reply #15 on: October 03, 2015, 10:57:17 PM »
Dave, this might be of use - Targeting your application for Windows
Quote
In Windows 8.1 and Windows 10, the GetVersion and GetVersionEx APIs have been deprecated and superseded by the Version Helper APIs. While you can still call the deprecated APIs, if your application does not specifically target Windows 8.1 or Windows 10, you will get Windows 8 version (6.2.0.0).

In order to target Windows 8.1 or Windows 10, you need to include the app manifest in the source file.

jj, you can still build exes for 2000 because the version helpers use APIs that 2000 has.
Attached is the header from the Win10 SDK.
I can walk on water but stagger on beer.

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #16 on: October 03, 2015, 11:43:34 PM »
The version helper can be very useful with a lib who include it's functions.
Quote
jj2007's GetVersionInfo, posted above, agrees, so apparently 8.1 = 6.3! Microsoft needs to hire better arithmeticians
The Major and minor version must be read with the help of:
https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms724833(v=vs.85).aspx
6.3 = Windows 8 or Windows Server 2012 R2
Fa is a musical note to play with CL

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #17 on: October 04, 2015, 03:08:58 AM »
good advice
Quote
In Windows 8.1 and Windows 10, the GetVersion and GetVersionEx APIs have been deprecated and superseded by the Version Helper APIs. While you can still call the deprecated APIs, if your application does not specifically target Windows 8.1 or Windows 10, you will get Windows 8 version (6.2.0.0).

In order to target Windows 8.1 or Windows 10, you need to include the app manifest in the source file

I try to made that without any modify on the answer of GetVersionInfoEx

I have added that to my rc file

Quote
#define _NT_TARGET_VERSION $(_NT_TARGET_VERSION_LATEST)
#define IDR_VERSION1 1
#define SXS_MANIFEST_RESOURCE_ID  1
#define SXS_MANIFEST "cpusys.manifest"
#define SXS_ASSEMBLY_NAME "Microsoft.Windows.Foo"
#define SXS_ASSEMBLY_VERSION 1.0   
#define SXS_ASSEMBLY_LANGUAGE_INDEPENDENT 1
#define SXS_MANIFEST_IN_RESOURCES 1

cpusys.manifest is the same as the html page
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: OS Info for Windows 8 and 10
« Reply #18 on: October 04, 2015, 05:13:21 AM »
jj, you can still build exes for 2000 because the version helpers use APIs that 2000 has.

Yes, it uses VerifyVersionInfoW, which in turn calls good ol' RtlGetVersion, the one I used in my code. Thanks for the header file, I had seen an unofficial one somewhere, good to have the original.

Quote
While you can still call the deprecated APIs, if your application does not specifically target Windows 8.1 or Windows 10, you will get Windows 8 version (6.2.0.0).

RtlGetVersion returns 6.3 on Windows 8.1, without manifest. The logic "manifest-wise my application is not specifically targeted for 8.1, so I want the OS to fake an 8.0" is rather redmondish  :eusa_boohoo:

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #19 on: October 04, 2015, 05:29:38 AM »
http://www.codeproject.com/Articles/678606/Part-Overcoming-Windows-s-deprecation-of-GetVe?msg=5080848#xx5080848xx

return 10.0 with Windows 10
invoke DllRtlGetVersion,TXT("ntdll.dll"),addr osvi ;GetVersionEx

Quote
.data
   osvi OSVERSIONINFOEX <>
.code
DllRtlGetVersion PROC  pnameddll:DWORD,  posversion:DWORD
         Local Hlib:DWORD
         Local  retour:DWORD
         mov retour,0 ;failed
   invoke LoadLibrary,pnameddll
   mov Hlib,eax
   .if eax != 0
      Invoke GetProcAddress,Hlib,TXT("RtlGetVersion")
      .if eax != 0
         mov edx,posversion
         mov [edx].OSVERSIONINFOEX.dwOSVersionInfoSize,sizeof OSVERSIONINFOEX
         push posversion
         call eax
         pop edx
         .if eax != 0
            mov retour,1      ;succès
         .endif      
      .endif   
      invoke FreeLibrary,Hlib
   .endif
   
 FindeDllRtlGetVersion:
         mov eax,retour
         ret
DllRtlGetVersion endp   

Fa is a musical note to play with CL

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #20 on: October 04, 2015, 06:24:59 AM »
Here a test prog

i find an inversion on:
Windows  OSVERSIONINFOEX.wProductType == VER_NT_WORKSTATION

To view Windows 10 in the zip,OSVERSIONINFOEX.wProductType != VER_NT_WORKSTATION

Perhaps is there the same problem with other system ??
« Last Edit: October 06, 2015, 12:11:49 AM by ToutEnMasm »
Fa is a musical note to play with CL

dedndave

  • Member
  • *****
  • Posts: 8787
  • Still using Abacus 2.0
    • DednDave
Re: OS Info for Windows 8 and 10
« Reply #21 on: October 04, 2015, 11:33:20 AM »
must be 64-bit, Yves - can't run it on XP   :(

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5338
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: OS Info for Windows 8 and 10
« Reply #22 on: October 04, 2015, 03:22:27 PM »
Seems to work OK on my Win7 64. The "Windows Server 2008 R2" is about of the same vintage which may account for the mis identification.


Intel(R) Core(TM) i7 CPU         860  @ 2.80GHz
Windows Server 2008 R2, Build S 7601


;constants switch for translate.inc
_WIN32_WINNT equ 00000601h
NTDDI_VERSION equ 06010000h
WINVER equ 06010000h

_MSC_VER equ   ;defaut value 1500
;Reports the major and minor versions of the compiler. For example, 1310
;for Microsoft Visual C++ .NET 2003. 1310 represents version 13 and a 1.0
;point release. The Visual C++ 2005 compiler version is 1400.

;Type cl /? at the command line to see the major and minor versions of
;your compiler along with the build number.
;http://msdn.microsoft.com/en-us/library/b0084kay(vs.80).aspx

_WIN32_IE equ  ;internet explorer version * 100h ,if 8 _WIN32_IE equ 800h
   include sdkddkver.sdk   
;How to COPY this ?
;select the text,CTRL-C to copy to the clipbord

hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: OS Info for Windows 8 and 10
« Reply #23 on: October 04, 2015, 04:54:34 PM »
Hutch,
What do you get from a simple commandline ver?

i guess that would formatted as "5.1.2600 SP 3.0"

Code: [Select]
RtlGetVersion   5.1 SP 3.0 build 2600
Suite mask      0100: SINGLEUSERTS
ProductType     WORKSTATION
CSDVersion      Service Pack 3

@Dave: Thanks :icon14: So far RtlGetVersion returns correct numbers for all OS versions, including Sinsi's 10.0. It seems to be the lowest level solution, except for reading the PEB directly.

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #24 on: October 04, 2015, 06:44:10 PM »
Quote
must be 64-bit, Yves - can't run it on XP 
Too bad,there is not real change that justify this.The code worked perfectly in my old xp.
It is 32 bit,it's not so easy to change from 32 to 64 in asm.
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: OS Info for Windows 8 and 10
« Reply #25 on: October 04, 2015, 07:22:17 PM »
must be 64-bit, Yves - can't run it on XP   :(

It is 32-bit indeed, just launch it with Olly. It displays a RichEd control with the text below.

@Yves: The cpu is OK but I'm definitely not running Windows Server 2008 R2 8)

Code: [Select]
       Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
Windows Server 2008 R2, Build S 7601


;constants switch for translate.inc
_WIN32_WINNT equ 00000601h
NTDDI_VERSION equ 06010000h
WINVER equ 06010000h

_MSC_VER equ   ;defaut value 1500
;Reports the major and minor versions of the compiler. For example, 1310
;for Microsoft Visual C++ .NET 2003. 1310 represents version 13 and a 1.0
;point release. The Visual C++ 2005 compiler version is 1400.

;Type cl /? at the command line to see the major and minor versions of
;your compiler along with the build number.
;http://msdn.microsoft.com/en-us/library/b0084kay(vs.80).aspx

_WIN32_IE equ  ;internet explorer version * 100h ,if 8 _WIN32_IE equ 800h
include sdkddkver.sdk
;How to COPY this ?
;select the text,CTRL-C to copy to the clipbord

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #26 on: October 05, 2015, 01:00:55 AM »

After some test,Rtlgetversion seems to be a not very good way.
Just answer 0 as wProductType.
The god (MSDN) way is this one:
Quote
To obtain the full version number for the operating system,
call the GetFileVersionInfo function on one of the system DLLs,
 such as Kernel32.dll, then call VerQueryValue to obtain
 the \\StringFileInfo\\<lang><codepage>\\ProductVersion subblock of the file
 version information.
Fa is a musical note to play with CL

adeyblue

  • Member
  • **
  • Posts: 89
    • Airesoft
Re: OS Info for Windows 8 and 10
« Reply #27 on: October 05, 2015, 02:29:31 AM »
Don't forget

void
__stdcall
RtlGetNtVersionNumbers(
   ULONG* pMajor,
   ULONG* pMinor,
   ULONG* pBuild
);

from XP onwards because 14 methods that return the version just wasn't enough.

ToutEnMasm

  • Member
  • *****
  • Posts: 1190
    • EditMasm
Re: OS Info for Windows 8 and 10
« Reply #28 on: October 05, 2015, 04:12:20 AM »
Only 14 methods ??????:
If it is a game , the more powerfull is dumpbin
He found "RtlGetNtProductType"
After an acces violation,RtlGetNtProductType PROTO product:LPDWORD
He return 1 (WORKSTATION on Windows 10)
I will try to fulfill others conditions.

 
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 8352
  • Assembler is fun ;-)
    • MasmBasic
Re: OS Info for Windows 8 and 10
« Reply #29 on: October 05, 2015, 05:07:34 AM »
After some test,Rtlgetversion seems to be a not very good way.

@Yves: Which test? Show me one example where RtlGetVersion doesn't return the correct OS version number.

@adeyblue: Nice find :t And it looks really, really foolproof :icon_mrgreen:

RtlGetNtVersionNumbers    Ú$  8BFF                     mov edi, edi
77AF6CEB                  ³.  55                       push ebp
77AF6CEC                  ³.  8BEC                     mov ebp, esp
77AF6CEE                  ³.  8B45 08                  mov eax, [ebp+8]
77AF6CF1                  ³.  85C0                     test eax, eax
77AF6CF3                  ³. 74 06                    jz short 77AF6CFB
77AF6CF5                  ³.  C700 06000000            mov dword ptr [eax], 6
77AF6CFB                  ³>  8B45 0C                  mov eax, [ebp+0C]
77AF6CFE                  ³.  85C0                     test eax, eax
77AF6D00                  ³. 74 06                    jz short 77AF6D08
77AF6D02                  ³.  C700 01000000            mov dword ptr [eax], 1


Code: [Select]
RtlGetNtVersionNumbers:
major   6
minor   1
build   7601