News:

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

GetVersionEx

Started by p0wder, July 13, 2006, 03:07:59 PM

Previous topic - Next topic

p0wder

I found some info on getting windows versions. I am trying to get a grasp on jmp's and blocks of code, versus using if () {} ... I am not interested in using the higher level .IF macro syntax, because I am trying to learn. When I try and assemble, I get the error:

"directive must be in control block"

any ideas?



.const

; Windows Versions
szOSTitle DB "Windows Version",0
szOSError DB "Error Determining 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

; Determine Windows Version
GetOS proc
MOV osinfo.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO
; Get Windows Version
INVOKE GetVersionEx, addr osinfo
; Test for success
CMP EAX, 0
JNE @F
    INVOKE MessageBox,NULL,ADDR szOSError,ADDR szOSTitle,MB_OK
    INVOKE ExitProcess, 0
@@:
CMP osinfo.dwMajorVersion, 5
JE five
five:
CMP osinfo.dwMinorVersion, 2
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWin2k3, ADDR osinfo.szCSDVersion
CMP osinfo.dwMinorVersion, 1
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWinXP, ADDR osinfo.szCSDVersion
CMP osinfo.dwMinorVersion, 0
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWin2k, ADDR osinfo.szCSDVersion
CMP osinfo.dwMajorVersion, 4
JE four
four:
CMP osinfo.dwMinorVersion, 0
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWinNT, ADDR osinfo.szCSDVersion
CMP osinfo.dwMinorVersion, 90
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWinME, ADDR osinfo.szCSDVersion   
CMP osinfo.dwMinorVersion, 10
JE @F
@@:
INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWin98, ADDR osinfo.szCSDVersion 
    INVOKE MessageBox,NULL, ADDR szOSUnknown, ADDR szOSTitle,MB_OK
    RET
.ENDIF
INVOKE MessageBox,NULL, ADDR buffer, ADDR szOSTitle,MB_OK
RET
GetOS endp

TNick

I don't know.. maybe you must have an .IF for that .ENDIF?

GM


TNick

QuoteCMP osinfo.dwMajorVersion, 5
      JE five
      five:
         CMP osinfo.dwMinorVersion, 2
         JE @F
         @@:
            INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWin2k3, ADDR osinfo.szCSDVersion
         CMP osinfo.dwMinorVersion, 1
         JE @F
         @@:
            INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWinXP, ADDR osinfo.szCSDVersion
         CMP osinfo.dwMinorVersion, 0
         JE @F
         @@:
            INVOKE wsprintf, ADDR buffer, ADDR format, ADDR szWin2k, ADDR osinfo.szCSDVersion
      CMP osinfo.dwMajorVersion, 4
      JE four


I think that this pice of code will be executed like this:
if osinfo.dwMinorVersion= 2 then let's jump to "five", else, let's continue with "five"
did you mean:


Quote     CMP osinfo.dwMajorVersion, 5
      JNE four
      five:
          ......
      four:
              CMP osinfo.dwMajorVersion, 4
              jne  three
     

dsouza123

A simple way to figure it out, is to assemble the version with .if .elseif .else .endif then look at the disassembly.
That should give you insight into coding the equivalent of the higher level constructs.
There is much to be gained by examining the assembly produced for your code by compilers and assemblers.

TNick

I think this is what you want to do:

Quote
.const

; Windows Versions
szOSTitle   DB "Windows Version",0
szOSError   DB "Error Determining 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

; Determine Windows Version
GetOS proc
   MOV osinfo.dwOSVersionInfoSize, SIZEOF OSVERSIONINFO
   ; Get Windows Version
   INVOKE GetVersionEx, addr osinfo
   ; Test for success
   CMP EAX, 0
   JNE @F
         INVOKE MessageBox,NULL,ADDR szOSError,ADDR szOSTitle,MB_OK
         INVOKE ExitProcess, 0
   @@:
      five:
      CMP osinfo.dwMajorVersion, 5
      JNE four
      
         CMP osinfo.dwMinorVersion, 2
         JNE @F
            mov   eax,   OFFSET szWin2k3
            jmp   IKnow_Is_
         @@:
         CMP osinfo.dwMinorVersion, 1
         JNE @F         
            mov   eax,   OFFSET szWinXP
            jmp   IKnow_Is_
         @@:
         CMP osinfo.dwMinorVersion, 0
         JNE @F
            mov   eax,   OFFSET szWin2k
            jmp   IKnow_Is_
         @@:
            jmp   Unknown
      four:
      CMP osinfo.dwMajorVersion, 4
      JNE Unknown
      four:
         CMP osinfo.dwMinorVersion, 0
         JNE @F         
            mov   eax,   OFFSET szWinNT
            jmp   IKnow_Is_
         @@:
         CMP osinfo.dwMinorVersion, 90
         JNE @F         
            mov   eax,   OFFSET szWinME   
            jmp   IKnow_Is_
         @@:
         CMP osinfo.dwMinorVersion, 10
         JNE @F         
            mov   eax,   OFFSET szWin98 
            jmp   IKnow_Is_
            @@:
               jmp   Unknown
   IKnow_Is_:   
      INVOKE wsprintf, ADDR buffer, ADDR format, eax, ADDR osinfo.szCSDVersion
      INVOKE MessageBox,NULL, ADDR buffer, ADDR szOSTitle,MB_OK
      RET
   Unknown:
         INVOKE MessageBox,NULL, ADDR szOSUnknown, ADDR szOSTitle,MB_OK
      RET
   
   
GetOS endp