I have some code i found to get the windows version, i am trying to make it 'lower level' so that i can learn masm32/asm better. here is what i have so far -



print macro lpszText:VARARG
LOCAL txt
.data
  txt DB lpszText,13,10,0
.code
  invoke StdOut, ADDR txt
ENDM

.data?


osinfo      OSVERSIONINFO <>
AppName    DB ?
tmp DD ?
buffer      db 512 dup (?)


.const


szOSError  DB "Error Determining Windows version",0
szOSUnknown DB "Unknown Version of Windows",0
szWin98      DB "Windows 98",0
szWinME      DB "Windows ME",0
szWinNT      DB "Windows NT",0
szWin2k      DB "Windows 2000",0
szWinXP      DB "Windows XP",0
szWin2k3      DB "Windows 2003",0

.code


GetOS proc
MOV osinfo.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO
; Get Windows Version
PUSH osinfo
call GetVersionEx
; Test for success
CMP EAX, 0
JE @F
@@:
  print szOSError
PUSH 0
  CALL ExitProcess
.IF osinfo.dwMajorVersion==5 &&osinfo.dwMinorVersion==2
invoke wsprintf,addr buffer,addr format,addr Win2k3,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==5 &&osinfo.dwMinorVersion==1
invoke wsprintf,addr buffer,addr format,addr WinXP,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==5 &&osinfo.dwMinorVersion==0
invoke wsprintf,addr buffer,addr format,addr Win2k,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==4 &&osinfo.dwMinorVersion==0
invoke wsprintf,addr buffer,addr format,addr WinNT,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==4 &&osinfo.dwMinorVersion==90
invoke wsprintf,addr buffer,addr format,addr WinME,addr osinfo.szCSDVersion   
.ELSEIF osinfo.dwMajorVersion==4 &&osinfo.dwMinorVersion==10
invoke wsprintf,addr buffer,addr format,addr Win98,addr osinfo.szCSDVersion 
.ELSE
invoke MessageBox,NULL,addr Upgrade,addr AppName,MB_OK
  print szOSUnknown
.ENDIF
print                    
invoke MessageBox,NULL,aDDr buffer,aDDr AppName,MB_OK
RET
GetOS endp


Any ideas what i am doing wrong?
Posted on 2006-07-10 19:26:51 by p0wder
Here is a striped down code which should work:

.486
.model flat, stdcall 
option casemap:none

include \masm32\include\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data

format db "%s %s",0

.data?

osinfo      OSVERSIONINFO <>
buffer      db 512 dup (?)

.const

AppName    DB "test app",0
szOSError  DB "Error Determining Windows version",0
szOSUnknown DB "Unknown Version of Windows",0
szWin98      DB "Windows 98",0
szWinME      DB "Windows ME",0
szWinNT      DB "Windows NT",0
szWin2k      DB "Windows 2000",0
szWinXP      DB "Windows XP",0
szWin2k3      DB "Windows 2003",0

.code

start:

MOV osinfo.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO
; Get Windows Version
PUSH offset osinfo
call GetVersionEx
; Test for success
CMP EAX, 0
JNE @F
  invoke MessageBox,NULL,aDDr szOSError,aDDr AppName,MB_OK
PUSH 0
  CALL ExitProcess
    @@:

.IF osinfo.dwMajorVersion==5 && osinfo.dwMinorVersion==2
invoke wsprintf,addr buffer,addr format,addr szWin2k3,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==5 && osinfo.dwMinorVersion==1
invoke wsprintf,addr buffer,addr format,addr szWinXP,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==5 && osinfo.dwMinorVersion==0
invoke wsprintf,addr buffer,addr format,addr szWin2k,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==4 && osinfo.dwMinorVersion==0
invoke wsprintf,addr buffer,addr format,addr szWinNT,addr osinfo.szCSDVersion
.ELSEIF osinfo.dwMajorVersion==4 && osinfo.dwMinorVersion==90
invoke wsprintf,addr buffer,addr format,addr szWinME,addr osinfo.szCSDVersion   
.ELSEIF osinfo.dwMajorVersion==4 && osinfo.dwMinorVersion==10
invoke wsprintf,addr buffer,addr format,addr szWin98,addr osinfo.szCSDVersion 
.ELSE
  invoke MessageBox,NULL,aDDr szOSUnknown,aDDr AppName,MB_OK
  PUSH 0
  CALL ExitProcess
.ENDIF
       
invoke MessageBox,NULL,aDDr buffer,aDDr AppName,MB_OK
PUSH 0
  CALL ExitProcess

end start


There were just to many errors and stuff that didn't made sense in the code you have provided. So I guess it'll be pointless to explain each fault. However if you have a specific question regarding something, don't hesitate to ask. We will be happy to help.
Posted on 2006-07-10 20:06:22 by arafel