News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetWindowsOS

Started by ecube, February 25, 2008, 11:08:48 AM

Previous topic - Next topic

ecube


I found a issue atleast in my windows.inc that OSVERSIONINFOEX seems to be outdated, heres some example code with the updated struct


.586
.model flat, stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

     CTEXT MACRO text:VARARG
            local TxtName
              .data
               TxtName BYTE text,0
              .code
            EXITM <ADDR TxtName>
     ENDM


GetWindowsOS proto :DWORD

.data?
;I added on a 'x' so it doesn't conflict with the previous definition
OSVERSIONINFOEXAX STRUCT
  dwOSVersionInfoSize   DWORD ?
  dwMajorVersion  DWORD ?
  dwMinorVersion  DWORD ?
  dwBuildNumber    DWORD ?
  dwPlatformId    DWORD ?
  szCSDVersion    BYTE  128  dup (?)
  wServicePackMajor WORD ?
  wServicePackMinor WORD ?
  wSuiteMask            WORD ?
  wProductType        BYTE ?
  wReserved             BYTE ?
OSVERSIONINFOEXAX ENDS

myOS byte 512 dup(?)

.code
start:
invoke GetWindowsOS,addr myOS
invoke MessageBox,0,addr myOS,NULL,MB_OK
invoke ExitProcess,0

GetWindowsOS proc oBuF:DWORD
Local osvi:OSVERSIONINFOEXAX
mov osvi.dwOSVersionInfoSize,SIZEOF OSVERSIONINFOEXAX
invoke GetVersionEx, ADDR osvi

.if osvi.dwPlatformId == VER_PLATFORM_WIN32_NT
.if osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0
.if osvi.wProductType==VER_NT_WORKSTATION
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows Vista")
.else
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows Server 2008")
.endif
.elseif osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows Server 2003")
.elseif osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows XP ")
.elseif osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows 2000 ")
.elseif osvi.dwMajorVersion <= 4
invoke lstrcpy,oBuF,CTEXT("Microsoft Windows NT ")
.endif
.endif
ret
GetWindowsOS endp
end start


Updated: I fixed the issue people were having below, it was the mov osvi.dwOSVersionInfoSize,SIZEOF OSVERSIONINFOEXAX which I accidently
had as mov osvi.dwOSVersionInfoSize,SIZEOF OSVERSIONINFOEXA

ecube

can someone with vista test this please, a friend tested who had vista and said it said win 2008?

six_L

tested on Vista Home Basic.
it was the Server 2008.
regards

evlncrn8

vista with the service pack shows up as windows .6001 build, which some detectors confuse with windows server 2008 because it has the .6001 as well as far as i remember

ic2

E^cube, I get only Windows XP but I have ServicePack2 included.  I added a example.  Both codes need to display all services packs also because it plays a very big part in determination these days.  We all seeing new things that we need to adjust to.

Quotea friend tested who had vista and said it said win 2008?
I didn't read your thread properly ... Now I see your point.   Interesting the MS code made provision to display new versions that way.  It still could be outdated or MS is leaving it up to the coders to make any needed adjustment.  Seems kind of cool that they don't have to go all out of their way.  I wonder how would it ajust for the new ServicePack just released for Vista.  This may be the next concern.

Now I see evlncrn8 is already addressing that... anyway another working example below:

[attachment deleted by admin]

ToutEnMasm

Hello,
This one is a translate of a sdk sample.Can you test it ?

[attachment deleted by admin]

ecube

ic2 I noticed you do major 6 and minor 1 for vista can someone with vista please test ic2's upload? tout your code works but doesn't include vista as you're aware of which is what i'm after. my code is based off http://msdn2.microsoft.com/en-us/library/ms724833(VS.85).aspx

"Because the version numbers for Windows Server 2008 and Windows Vista are identical, you must also test whether the wProductType member is VER_NT_WORKSTATION. If wProductType is VER_NT_WORKSTATION, the operating system is Windows Vista; otherwise, it is Windows Server 2008."

which doesn't seem to be working correctly.

GregL

E^cube,

I'm running Windows Vista Home Premium with no Service Packs.

With the code you posted, I get "Microsoft Windows Server 2008".

Your code does use the same method as the MSDN example code.

Here's what I get for OSVERSIONINFOEX.

OSVERSIONINFOEX
dwOSVersionInfoSize 0x00000094  unsigned long
 dwMajorVersion      0x00000006  unsigned long
 dwMinorVersion      0x00000000  unsigned long
 dwBuildNumber       0x00001770  unsigned long
 dwPlatformId        0x00000002  unsigned long
 szCSDVersion        0x00        unsigned char
 wServicePackMajor   0x0000      unsigned short
 wServicePackMinor   0x0000      unsigned short
 wSuiteMask          0x0000      unsigned short
 wProductType        0x00        unsigned char
 wReserved           0x00        unsigned char

wProductType = 0

???


GregL

E^cube,

I got different results with the C code. Which led me to the problem.


mov osvi.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO


should be


mov osvi.dwOSVersionInfoSize, SIZEOF OSVERSIONINFOEX


It works correctly after changing that.


ecube

haha wow! I can't believe I missed that,it's been starring me in the face the entire time, I must of glanced over the code atleast 20 times, nice find Greg, thanks!

GregL

E^cube,

It was staring me in the face for a while too.  :bg 


ic2

I was working with that code a long time ago and was only guesting what the Vista numbers might be based on previous values.  I just though it in there to get it out the way.   I founded nothing much about Vista back than.  I was stuck on XP.  I should have said something... I wasn't thinking. Sorry E^cube.

GregL

While I was at it I translated the rest of the MSDN example "Getting the System Version". Tested on Windows Vista Home Premium, Windows XP SP2 and Windows 2000 SP4.


[attachment deleted by admin]

GregL

Updated to support Windows 7. Tested on Windows 7 Professional and Windows Vista Home Premium.

ragdog

Thanks it works fine on win 7 :U