Page 1 of 2

GetVersionEx (help me test this code)

Posted: Wed Jun 22, 2005 7:33 pm
by Killswitch
I've just written a procedure to determine the version of windows someone is running. It works on my machine but I need to test it on different versions of Windows.

Code: Select all


Procedure.s WindowsVersion()

  Version.OSVERSIONINFO
  Version\dwOSVersionInfoSize=SizeOf(OSVERSIONINFO)
  GetVersionEx_(Version)

  Select Version\dwMajorVersion
  
    Case 4 ;Windows NT 4.0, Windows Me, Windows 98, or Windows 95
    
      Select Version\dwMinorVersion
      
        Case 10
          ProcedureReturn "Windows 98"
        
        Case 90
          ProcedureReturn "Windows ME"
        
        Default
        
          If Version\dwPlatformID=#VER_PLATFORM_WIN32_WINDOWS 
            ProcedureReturn "Windows 95"
          EndIf
      
      EndSelect
    
    Case 5 ;Windows Server 2003, Windows XP, or Windows 2000
      
      Select Version\dwMinorVersion
      
        Case 1
          ProcedureReturn "Windows XP"
      
        Case 2
          ProcedureReturn "Windows Server 2003"
        
        Default
          ProcedureReturn "Windows 2000"
     
      EndSelect
    
  EndSelect
  
EndProcedure

MessageRequester("Version",WindowsVersion())

Could you please test this on your computer, then post the result and your actual OS.

Thanks a lot!

(BTW: Proceedure is free for anyone to use, can't gaurentee it'll work 100% atm).

Posted: Wed Jun 22, 2005 7:56 pm
by dontmailme
Correctly reported Win2k for me!

Cheers!

Posted: Wed Jun 22, 2005 8:19 pm
by utopiomania
'Result = OSVersion()' is in the PureBasic box :?:

Posted: Wed Jun 22, 2005 9:34 pm
by PB
> 'Result = OSVersion()' is in the PureBasic box

Yeah, I thought this was an old thread at first. :shock:

Posted: Wed Jun 22, 2005 11:17 pm
by Killswitch
Here's the explination:

I'm writing my own (interpreted) BASIC variant in PureBasic. As I am not allowed to wrap any of PBs existing commands (according to the licence and a thread I made about the topic) I basically have to write each of the commands from scratch.

This is where this procedure comes in.

Posted: Thu Jun 23, 2005 12:26 am
by PB
Ah, now we understand. :)

Posted: Thu Jun 23, 2005 4:45 pm
by dontmailme
PB wrote:Ah, now we understand. :)
So now you're going to post the result ?!

;)

Posted: Thu Jun 23, 2005 9:17 pm
by Killswitch
It would really help me if you could post your results - espically if your on 95, 98 or ME!

Posted: Thu Jun 23, 2005 9:32 pm
by PB
> So now you're going to post the result ?! ;)

Okay :)

Win XP Pro returns Windows XP.
Win 2K Pro returns Windows 2000.
Win 98 SE returns Windows 98.
Win ME returns Windows ME.

Not tested on 95 or NT as I don't have them installed at the moment (obsolete).
If you really need to know the results, let me know and I'll install them...

Posted: Thu Jun 23, 2005 11:19 pm
by Killswitch
Sweet, thank you very much PB - if they all work I'm sure NT and 95 work!

Posted: Thu Nov 17, 2005 9:13 pm
by techjunkie
An updated version, but I'm not sure if Vista and Longhorn works ok. Can anyone confirm?

It seems like the OSVERSIONINFO has change and should contain a "wProductType", or is that in OSVERSIONINFOEX?!?!

Code: Select all

Procedure.s WindowsVersion() 

  Version.OSVERSIONINFO 
  Version\dwOSVersionInfoSize=SizeOf(OSVERSIONINFO) 
  GetVersionEx_(Version) 

  Select Version\dwMajorVersion 

    Case 4 ;Windows NT 4.0, Windows Me, Windows 98, or Windows 95 
      Select Version\dwMinorVersion 
        Case 10 
          ProcedureReturn "Windows 98"  
        Case 90 
          ProcedureReturn "Windows ME" 
        Default 
          If Version\dwPlatformID = #VER_PLATFORM_WIN32_WINDOWS 
            ProcedureReturn "Windows 95"
          ElseIf Version\dwPlatformID = #VER_PLATFORM_WIN32_NT
            ProcedureReturn "Windows NT"
          Else
            ProcedureReturn "Unknown OS"
          EndIf
      EndSelect 
    
    Case 5 ;Windows Server 2003, Windows XP, or Windows 2000 
      Select Version\dwMinorVersion
        Case 0
          ProcedureReturn "Windows 2000"      
        Case 1 
          ProcedureReturn "Windows XP"       
        Case 2 
          ProcedureReturn "Windows Server 2003"         
        Default 
          ProcedureReturn "Unknown OS"       
      EndSelect 

    Case 6 ;Windows Server "Longhorn" or "Microsoft Windows Vista"
      Select Version\dwMinorVersion
        Case 0
          If Version\dwPlatformID = #VER_PLATFORM_WIN32_NT
            ProcedureReturn "Microsoft Windows Vista" 
          Else
            ProcedureReturn "Windows Server Longhorn"
          EndIf
        Default
          ProcedureReturn "Unknown OS"
      EndSelect
  EndSelect 
  
EndProcedure 

MessageRequester("Version",WindowsVersion()) 

Posted: Thu Nov 17, 2005 9:20 pm
by rsts
Fine for XP.

Not sure if I still have my vista cd but if it hasn't shown up in a day or so I'll see if i can re-install it (it's pretty much useless, that's why I overwrote the partition).

cheers

Posted: Fri Nov 18, 2005 5:55 am
by PB
> I'm not sure if Vista and Longhorn works

@Fred: Maybe PureBasic's OSVersion() command can be updated to get
these versions of Windows too? ;)

Posted: Fri Nov 18, 2005 4:49 pm
by techjunkie
PB wrote:> I'm not sure if Vista and Longhorn works

@Fred: Maybe PureBasic's OSVersion() command can be updated to get
these versions of Windows too? ;)
Yeah!

Here is a good link about how to get the new versions, but I'm to lazy to convert it... :lol:

http://msdn.microsoft.com/library/defau ... ersion.asp

Posted: Fri Nov 18, 2005 6:39 pm
by rsts
I should get a chance to re-install vista later today and I'll let you know.

This time I'll keep it available in case there are other questions.

cheers