[Implemented] OSVersion() Update?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

[Implemented] OSVersion() Update?

Post by GeoTrail »

When is the OSVersion() going to be updated with the #PB_OS_Windows_Vista constant?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I wrote alittle code here that'll help me while I wait for an update of the OSVersion() procedure:

Code: Select all

Procedure.s GetOSVersion()
  Macro GetWindowsDirectory()
    GetEnvironmentVariable("windir")
  EndMacro
  WinDir$ = GetWindowsDirectory()+"\"
  Select OSVersion()
    Case #PB_OS_Windows_NT3_51
      Result$ = "Windows NT 3.51"      
    Case #PB_OS_Windows_95
      Result$ = "Windows 95"
    Case #PB_OS_Windows_NT_4
      Result$ = "Windows NT 4"
    Case #PB_OS_Windows_98
      Result$ = "Windows 98"
    Case #PB_OS_Windows_ME
      Result$ = "Windows ME"
    Case #PB_OS_Windows_2000
      Result$ = "Windows 2000"
    Case #PB_OS_Windows_XP
      Result$ = "Windows XP"
    Case #PB_OS_Windows_Server_2003
      Result$ = "Windows Server 2003"
    Case #PB_OS_Windows_Future
      If FileSize(WinDir$+"HomePremium.xml")
        Result$ = "Windows Vista Home Premium"
      ElseIf FileSize(WinDir$+"HomeBasic.xml")
        Result$ = "Windows Vista Home Basic"
      ElseIf FileSize(WinDir$+"HomeBasicN.xml")
        Result$ = "Windows Vista Home BasicN"
      ElseIf FileSize(WinDir$+"Business.xml")
        Result$ = "Windows Vista Business"
      ElseIf FileSize(WinDir$+"BusinessN.xml")
        Result$ = "Windows Vista BusinessN"
      ElseIf FileSize(WinDir$+"Ultimate.xml")
        Result$ = "Windows Vista Ultimate"
      ElseIf FileSize(WinDir$+"Starter.xml")
        Result$ = "Windows Vista Starter"
      Else
        Result$ = "Windows Vista"
      EndIf
  EndSelect
  ProcedureReturn Result$
EndProcedure

MessageRequester("Windows Version Checker", "This is a test app for " + GetOSVersion() + ".")
Last edited by GeoTrail on Tue Nov 14, 2006 10:07 pm, edited 1 time in total.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

For those how don't use the Droopy lib :

Code: Select all

Macro GetWindowsDirectory()
  GetEnvironmentVariable("windir")
EndMacro
Dri
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

How do you know the user doesn't have more of those xml files after an upgrade, for example from home to premium?
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Why not use #PB_OS_Windows_Future until there is no real constant? :wink:
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Dr. Dri wrote:For those how don't use the Droopy lib :

Code: Select all

Macro GetWindowsDirectory()
  GetEnvironmentVariable("windir")
EndMacro
Dri
I've updated my code :)
Trond wrote:How do you know the user doesn't have more of those xml files after an upgrade, for example from home to premium?
I don't, but if they did, then the old file would be deleted and replaced with the newly upgraded version :)
AND51 wrote:Why not use #PB_OS_Windows_Future until there is no real constant? :wink:
What do you mean?
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
SoulReaper
Enthusiast
Enthusiast
Posts: 372
Joined: Sun Apr 03, 2005 2:14 am
Location: England

Post by SoulReaper »

Nice one Geotrail :)
This will be most useful :wink:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

GeoTrail, could you run this on your Vista and see what you get, I'd be interested to know:

Code: Select all

vi.OSVERSIONINFO
vi\dwOsVersionInfoSize = SizeOf(OSVERSIONINFO)
GetVersionEx_(@vi)
out$ =  "Major Version: "+Str(vi\dwMajorVersion)+ #CRLF$
out$ +  "Minor Version: "+Str(vi\dwMinorVersion) + #CRLF$
out$ +  "Build Number: "+Str(vi\dwBuildNumber) + #CRLF$
out$ +  "Platform ID: "+Str(vi\dwPlatformId) + #CRLF$
out$ +  PeekS(@vi\szCSDversion) + #CRLF$
MessageRequester("OS Version Information:",out$,#MB_ICONINFORMATION)
Presumably testing for some of the data this API returns would be a fairly reliable way to test. I get a little nervous about looking on the disk for specific files, it just doesn't seem like a very bulletproof approach to me.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Here's the result netmaestro:
Major Version: 6
Minor Version: 0
Build Number: 6000
Platform ID: 2
netmaestro wrote:I get a little nervous about looking on the disk for specific files, it just doesn't seem like a very bulletproof approach to me.
Yeah that's what my girlfriend said about rubber over three years ago :shock: hehehe
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

Code: Select all

Procedure.s MyOSVersion()
  Result.s = "Windows Unknown"
  
  osvi.OSVERSIONINFO
  osvi\dwOsVersionInfoSize = SizeOf(OSVERSIONINFO)
  If GetVersionEx_(@osvi)
    Select osvi\dwPlatformId
      
      Case 1
        
        If osvi\dwMajorVersion = 4
          Select osvi\dwMinorVersion
            Case 0
              Result = "Windows 95"
            Case 10
              Result = "Windows 98"
            Case 90
              Result = "Windows ME"
          EndSelect
        EndIf
        
      Case 2
        
        osviex.OSVERSIONINFOEX
        osviex\dwOsVersionInfoSize = SizeOf(OSVERSIONINFOEX)
        If GetVersionEx_(@osviex)
          Select osviex\dwMajorVersion
            
            Case 3
              Result = "Windows NT3"
            Case 4
              Result = "Windows NT4"
            Case 5
              Select osviex\dwMinorVersion
                Case 0
                  Result = "Windows 2000"
                Case 1
                  Result = "Windows XP"
                Case 2
                  If osviex\wProductType = 1
                    Result = "Windows XP";64Bit
                  Else
                    Result = "Windows Server 2003"
                  EndIf
              EndSelect
            Case 6
              Select osviex\dwMinorVersion
                Case 0
                  If osviex\wProductType = 1
                    Result = "Windows Vista"
                  Else
                    Result = "Windows Server 2008"
                  EndIf
              EndSelect
              
          EndSelect
        EndIf
        
    EndSelect
  EndIf
  
  ProcedureReturn Result
EndProcedure

MessageRequester("OS Version", MyOSVersion())
i hope i havent made any mistakes. :P

edit: typos removed.
edit2: added NT3 detection and changed "Windows Server Longhorn" to "Windows Server 2008" its now the official name by microsoft. i am not sure if the NT3 detection will work properly, i dont have any chance to test it.


c ya,
nco2k
Last edited by nco2k on Wed Nov 22, 2006 8:50 pm, edited 2 times in total.
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

It says my OS is Mac Linux Windows. But hey :lol:
Naaahh just kiddin'n. It's working fine here on Vista.
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Looks good to me, nco2k. Good work!
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

@GeoTrail
wtf?! dont scare me like that. :lol:

@netmaestro
thx, but it was your code snippet what led me to the allmighty winsdk / msdn online docs. :oops: :D

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You hit on my strategy - post just enough to get someone else interested in doing the heavy lifting, then copy/save his post! Works every time :D
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

GeoTrail wrote:
AND51 wrote:Why not use #PB_OS_Windows_Future until there is no real constant? :wink:
What do you mean?
Please, have a closer look at the help:
PB Help, OSVersion() wrote: #PB_OS_Windows_NT3_51 = 5
#PB_OS_Windows_95 = 10
#PB_OS_Windows_NT_4 = 20
#PB_OS_Windows_98 = 30
#PB_OS_Windows_ME = 40
#PB_OS_Windows_2000 = 50
#PB_OS_Windows_XP = 60
#PB_OS_Windows_Server_2003 = 65
#PB_OS_Windows_Future = 100 ; neue Windows Version (nicht existent, als das Programm geschrieben wurde)
The german annotation says: "New windows version (not existant, when the program was written)



Even, if you don't want to use the Future-constant, there is an other way to detect Vista, Although, there is no vista-constant:
Did you already recognize, the the values of these constants are sorted ascending?

The newer the OS version is, the higher is the value of the constant. This means, that

Code: Select all

If OSVersion() > #PB_OS_Windows_Server_2003
     Debug "Your OS is newer than Win2003"
EndIf
should be true. This code, executed on a vista-system, would show the message.


I hope, you know that I'm aiming at in this post.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
Post Reply