The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
December 07, 2022, 02:39:04 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Laboratory (Moderator: Mark_Larson)
| | |-+  GetWindowsOS
« previous next »
Pages: [1] 2 Print
Author Topic: GetWindowsOS  (Read 13772 times)
ecube
Guest


Email
GetWindowsOS
« 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

Code:
.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
« Last Edit: May 10, 2009, 03:14:45 PM by E^cube » Logged
ecube
Guest


Email
Re: GetWindowsOS
« Reply #1 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?
Logged
six_L
The Poor English and ASM
Member
*****
Posts: 311


see you, see me, see you...


Re: GetWindowsOS
« Reply #2 on: February 29, 2008, 05:17:39 AM »

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

regards
evlncrn8
Member
*****
Posts: 320


Re: GetWindowsOS
« Reply #3 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
Logged
ic2
Guest


Email
Re: GetWindowsOS
« Reply #4 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.

Quote
a 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]
Logged
ToutEnMasm
Member
*****
Gender: Male
Posts: 1555


FA is a musical note to play with cl


Re: GetWindowsOS
« Reply #5 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]
Logged

ecube
Guest


Email
Re: GetWindowsOS
« Reply #6 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.
Logged
GregL
Member
*****
Gender: Male
Posts: 1897



Re: GetWindowsOS
« Reply #7 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

???

Logged
GregL
Member
*****
Gender: Male
Posts: 1897



Re: GetWindowsOS
« Reply #8 on: March 01, 2008, 11:58:13 PM »

E^cube,

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

Code:
mov osvi.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO

should be

Code:
mov osvi.dwOSVersionInfoSize, SIZEOF OSVERSIONINFOEX

It works correctly after changing that.

Logged
ecube
Guest


Email
Re: GetWindowsOS
« Reply #9 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!
Logged
GregL
Member
*****
Gender: Male
Posts: 1897



Re: GetWindowsOS
« Reply #10 on: March 02, 2008, 03:38:24 AM »

E^cube,

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

Logged
ic2
Guest


Email
Re: GetWindowsOS
« Reply #11 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.
Logged
GregL
Member
*****
Gender: Male
Posts: 1897



Re: GetWindowsOS
« Reply #12 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". Tested on Windows Vista Home Premium, Windows XP SP2 and Windows 2000 SP4.


[attachment deleted by admin]
Logged
GregL
Member
*****
Gender: Male
Posts: 1897



Re: GetWindowsOS
« Reply #13 on: August 22, 2010, 03:10:21 AM »

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

* GetOsVersion.zip (4.26 KB - downloaded 455 times.)
Logged
ragdog
Member
*****
Posts: 1008


Re: GetWindowsOS
« Reply #14 on: August 22, 2010, 12:45:15 PM »

Thanks it works fine on win 7 ThumbsUp
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!