Page 1 of 2

[Implemented] OSVersion() Update?

Posted: Tue Nov 14, 2006 3:49 pm
by GeoTrail
When is the OSVersion() going to be updated with the #PB_OS_Windows_Vista constant?

Posted: Tue Nov 14, 2006 4:34 pm
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() + ".")

Posted: Tue Nov 14, 2006 8:34 pm
by Dr. Dri
For those how don't use the Droopy lib :

Code: Select all

Macro GetWindowsDirectory()
  GetEnvironmentVariable("windir")
EndMacro
Dri

Posted: Tue Nov 14, 2006 8:42 pm
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?

Posted: Tue Nov 14, 2006 9:41 pm
by AND51
Why not use #PB_OS_Windows_Future until there is no real constant? :wink:

Posted: Tue Nov 14, 2006 10:09 pm
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?

Posted: Wed Nov 15, 2006 1:10 am
by SoulReaper
Nice one Geotrail :)
This will be most useful :wink:

Posted: Wed Nov 15, 2006 2:16 am
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.

Posted: Wed Nov 15, 2006 5:18 am
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

Posted: Wed Nov 15, 2006 5:45 am
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

Posted: Wed Nov 15, 2006 5:49 am
by GeoTrail
It says my OS is Mac Linux Windows. But hey :lol:
Naaahh just kiddin'n. It's working fine here on Vista.

Posted: Wed Nov 15, 2006 5:50 am
by netmaestro
Looks good to me, nco2k. Good work!

Posted: Wed Nov 15, 2006 6:15 am
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

Posted: Wed Nov 15, 2006 6:18 am
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

Posted: Wed Nov 15, 2006 3:17 pm
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.