The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: ecube on February 25, 2008, 11:08:48 AM

Title: GetWindowsOS
Post by: ecube on February 25, 2008, 11:08:48 AM

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
Title: Re: GetWindowsOS
Post by: ecube on February 29, 2008, 04:16:12 AM
can someone with vista test this please, a friend tested who had vista and said it said win 2008?
Title: Re: GetWindowsOS
Post by: six_L on February 29, 2008, 05:17:39 AM
tested on Vista Home Basic.
it was the Server 2008.
Title: Re: GetWindowsOS
Post by: evlncrn8 on February 29, 2008, 05:48:27 PM
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
Title: Re: GetWindowsOS
Post by: ic2 on March 01, 2008, 05:40:19 AM
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]
Title: Re: GetWindowsOS
Post by: ToutEnMasm on March 01, 2008, 07:25:14 AM
Hello,
This one is a translate of a sdk sample.Can you test it ?

[attachment deleted by admin]
Title: Re: GetWindowsOS
Post by: ecube on March 01, 2008, 08:59:35 AM
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.
Title: Re: GetWindowsOS
Post by: GregL on March 01, 2008, 11:03:20 PM
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

???

Title: Re: GetWindowsOS
Post by: GregL on March 01, 2008, 11:58:13 PM
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.

Title: Re: GetWindowsOS
Post by: ecube on March 02, 2008, 02:34:15 AM
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!
Title: Re: GetWindowsOS
Post by: GregL on March 02, 2008, 03:38:24 AM
E^cube,

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

Title: Re: GetWindowsOS
Post by: ic2 on March 02, 2008, 05:40:37 AM
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.
Title: Re: GetWindowsOS
Post by: GregL on March 06, 2008, 07:00:46 PM
While I was at it I translated the rest of the MSDN example "Getting the System Version (http://msdn2.microsoft.com/en-us/library/ms724429(VS.85).aspx)". Tested on Windows Vista Home Premium, Windows XP SP2 and Windows 2000 SP4.


[attachment deleted by admin]
Title: Re: GetWindowsOS
Post by: GregL on August 22, 2010, 03:10:21 AM
Updated to support Windows 7. Tested on Windows 7 Professional and Windows Vista Home Premium.
Title: Re: GetWindowsOS
Post by: ragdog on August 22, 2010, 12:45:15 PM
Thanks it works fine on win 7 :U
Title: Re: GetWindowsOS
Post by: dedndave on August 22, 2010, 04:02:49 PM
Dave  <----- chopped liver   :lol
i guess we all get turns, Greg
Title: Re: GetWindowsOS
Post by: GregL on August 23, 2010, 03:12:27 AM
Quote from: dedndaveDave  <----- chopped liver   lol
i guess we all get turns, Greg

Dave,

I think your OSInfo program is great, it gives a lot more information than my GetOSVersion program.

My code is just a MASM32 translation of the MSDN example C code for "Getting the System Version (http://msdn.microsoft.com/en-us/library/ms724429%28VS.85%29.aspx)".
Title: Re: GetWindowsOS
Post by: frktons on September 25, 2010, 02:23:37 AM
Quote from: GregL on August 22, 2010, 03:10:21 AM
Updated to support Windows 7. Tested on Windows 7 Professional and Windows Vista Home Premium.


Tested on Windows 7 Ultimate Edition 64 bit.  :U

Nice work Greg.

Frank
Title: Re: GetWindowsOS
Post by: GregL on September 25, 2010, 08:01:47 PM
Thanks, Frank.