Code archives/Miscellaneous/What kind of OS?
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Find the current OS with a WINAPI Call as TYPE and as BANK Funktion | |||||
; ONLY FOR THE TYPE VERSION--NUR FÜR DIE TYPE VERSION------------- ; ; in dem USERLIBS Verzeichnis muß sich die kernel32.decls Datei befinden ; in the USERLIBS must be the file kernel32.decls ;.lib "kernel32.dll" ;api_GetVersionEx% (lpVersionInformation*) : "GetVersionExA" ; ; ONLY FOR THE TYPE VERSION--NUR FÜR DIE TYPE VERSION------------- ; ONLY FOR THE BANK VERSION--NUR FÜR DIE BANK VERSION------------- ; ; in dem USERLIBS Verzeichnis muß sich die kernel32.decls Datei befinden ; in the USERLIBS must be the file kernel32.decls ;.lib "kernel32.dll" ;api_RtlMoveMemory(Destination*,Source,Length) : "RtlMoveMemory" ;api_GetVersionEx% (lpVersionInformation*) : "GetVersionExA" ; in dem USERLIBS Verzeichnis muß sich die comdlg32.decls Datei befinden ; in the USERLIBS must be the file comdlg32.decls ;.lib "comdlg32.dll" ;api_GetOpenFileName% (pOpenfilename*) : "GetOpenFileNameA" ;api_GetSaveFileName% (pOpenfilename*) : "GetSaveFileNameA" ; ; ONLY FOR THE BANK VERSION--NUR FÜR DIE BANK VERSION------------- ; WELCHES BETRIEBSSYTEM HAST DU? WHAT KIND OF OS DO YOU HAVE? ; Zwei verschiedene Möglichkeiten um das Betriebssystem zu mit WinApi Befehlen ; zu erkennen. Einmal als Type Befehl und einmal mit Bank Befehlen ; ; Michael Paulwitz () 1.2004 ; Idee nachgebaut von http://www.activevb.de/tipps/vb6tipps/tipp0129.html ; ; Two different Version of OS recognition. One with Type, one with Bank ; Idee from the side http://www.activevb.de/tipps/vb6tipps/tipp0129.html Type OSVERSIONINFO Field dwOSVersionInfoSize Field dwMajorVersion Field dwMinorVersion Field dwBuildNumber Field dwPlatformId Field szCSDVersion$ End Type Print "Typeversion = "+GetVersiontype$ () Print "Bankversion = "+GetVersionbank$ () While Not KeyDown(1) Wend End Function GetVersiontype$ () ; Type Version der Betriebssystemerkennung ; Type Version of the OS Recognition OS.OSVERSIONINFO = New OSVERSIONINFO OS\dwOSVersionInfoSize=148 OS\szCSDVersion$=String$ (Chr$(0), 128) api_GetVersionEx (OS) VER_PLATFORM_WIN32s = 0 VER_PLATFORM_WIN32_WINDOWS = 1 VER_PLATFORM_WIN32_NT = 2 If (OS\dwBuildNumber And $FFFF) > $7FFF Then BuildNr = (OS\dwBuildNumber And $FFFF) - $10000 Else BuildNr = OS\dwBuildNumber And $FFFF EndIf If OS\dwPlatformId = VER_PLATFORM_WIN32_NT Then If OS\dwMajorVersion = 4 Then OSString$ = "Windows NT" ElseIf OS\dwMajorVersion = 5 Then If OS\dwMinorVersion = 0 Then OSString$ = "Windows 2000" ElseIf OS\dwMinorVersion = 1 Then OSString = "Windows XP" EndIf EndIf ElseIf OS\dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then If (OS\dwMajorVersion > 4) Or (OS\dwMajorVersion = 4 And OS\dwMinorVersion = 10) Then If BuildNr = 1998 Then OSString$ = "Windows 98" Else OSString$ = "Windows 98 SE" EndIf ElseIf (OS\dwMajorVersion = 4 And OS\dwMinorVersion = 0) Then OSString$ = "Windows 95" ElseIf (OS\dwMajorVersion = 4 And OS\dwMinorVersion = 90) Then OSString$ = "Windows ME" End If ElseIf OS\dwPlatformId = VER_PLATFORM_WIN32s Then OSString$ = "Windows 32s" End If Return OSString$ End Function Function GetVersionBank$ () ; Bank Version der Betriebssystemerkennung ; Bank Version of the OS Recognition nextOffset%=0 theBank=CreateBank(148) dwOSVersionInfoSize=148 PokeInt theBank,nextOffset%,dwOSVersionInfoSize nextOffset%=nextOffset%+4 dwMajorVersion=0 PokeInt theBank,nextOffset%,dwMajorVersion nextOffset%=nextOffset%+4 dwMinorVersion=0 PokeInt theBank,nextOffset%,dwMinorVersion nextOffset%=nextOffset%+4 dwBuildNumber=0 PokeInt theBank,nextOffset%,dwBuildNumber nextOffset%=nextOffset%+4 dwPlatformId=0 PokeInt theBank,nextOffset%,dwPlatformId nextOffset%=nextOffset%+4 szCSDVersion$=String$ (" ", 128) szCSDVersion_ = CreateBank(Len(szCSDVersion$)) string_in_bank(szCSDVersion$,szCSDVersion_) PokeInt theBank,nextOffset%,AddressOf(szCSDVersion_) api_GetVersionEx (thebank) nextOffset%=0 dwOSVersionInfoSize = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwMajorVersion = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwMinorVersion = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwBuildNumber = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwPlatformId = PeekInt (thebank,nextOffset%) FreeBank theBank FreeBank szCSDVersion_ VER_PLATFORM_WIN32s = 0 VER_PLATFORM_WIN32_WINDOWS = 1 VER_PLATFORM_WIN32_NT = 2 If (dwBuildNumber And $FFFF) > $7FFF Then BuildNr = (dwBuildNumber And $FFFF) - $10000 Else BuildNr = dwBuildNumber And $FFFF EndIf If dwPlatformId = VER_PLATFORM_WIN32_NT Then If dwMajorVersion = 4 Then OSString$ = "Windows NT" ElseIf dwMajorVersion = 5 Then If dwMinorVersion = 0 Then OSString$ = "Windows 2000" ElseIf dwMinorVersion = 1 Then OSString = "Windows XP" EndIf EndIf ElseIf dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then If (dwMajorVersion > 4) Or (dwMajorVersion = 4 And dwMinorVersion = 10) Then If BuildNr = 1998 Then OSString$ = "Windows 98" Else OSString$ = "Windows 98 SE" EndIf ElseIf (dwMajorVersion = 4 And dwMinorVersion = 0) Then OSString$ = "Windows 95" ElseIf (dwMajorVersion = 4 And dwMinorVersion = 90) Then OSString$ = "Windows ME" End If ElseIf dwPlatformId = VER_PLATFORM_WIN32s Then OSString$ = "Windows 32s" End If Return OSString$ End Function Function AddressOf(Bank) ; Find the correct Adress of a Bank (for C *Pointer) Local Address = CreateBank(4) api_RtlMoveMemory(Address,Bank+4,4) Return PeekInt(Address,0) End Function Function string_in_bank(s$,bankhandle) ; Put a String in a Bank Local pos=1 Local pos2=0 Repeat PokeByte(bankhandle,pos2,Asc(Mid(s$,pos,Len(s$)))) pos=pos+1 pos2=pos2+1 Until pos=Len(s$)+1 End Function Function bank_in_string$(bankhandle) ; Get a String from a Bank Local s$="" Local pos=0 Repeat s$=s$+Chr(PeekByte(bankhandle,pos)) pos=pos+1 Until pos=BankSize(bankhandle) s$=Replace$(s$,Chr(0)," ") Return s$ End Function |
Comments
| ||
Thanks to help from John Blackledger, xlsior, Ked and Warner this should be an update to include the newer windows operating systems such as Vista and Windows 7 I only made use of the 'bank' functionality for this update, but by including a new function "ResolveOSName$()" it should be fairly straightforward to modify the "Type" version too. ; Michael Paulwitz () 1.2004 ;Modified By Malice to incorporate newer windows versions 2009 Graphics 800,600 Const VER_PLATFORM_WIN32s = 0 Const VER_PLATFORM_WIN32_WINDOWS = 1 Const VER_PLATFORM_WIN32_NT = 2 Print GetOSVersion$ () While Not KeyDown(1) Wend End Function GetOSVersion$() ; Bank Version of the OS Recognition Local OSString$ nextOffset%=0 theBank=CreateBank(148) dwOSVersionInfoSize=148 PokeInt theBank,nextOffset%,dwOSVersionInfoSize nextOffset%=nextOffset%+4 dwMajorVersion=0 PokeInt theBank,nextOffset%,dwMajorVersion nextOffset%=nextOffset%+4 dwMinorVersion=0 PokeInt theBank,nextOffset%,dwMinorVersion nextOffset%=nextOffset%+4 dwBuildNumber=0 PokeInt theBank,nextOffset%,dwBuildNumber nextOffset%=nextOffset%+4 dwPlatformId=0 PokeInt theBank,nextOffset%,dwPlatformId nextOffset%=nextOffset%+4 szCSDVersion$=String$ (" ", 128) szCSDVersion_ = CreateBank(Len(szCSDVersion$)) string_in_bank(szCSDVersion$,szCSDVersion_) PokeInt theBank,nextOffset%,AddressOf(szCSDVersion_) api_GetVersionEx(thebank) nextOffset%=0 dwOSVersionInfoSize = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwMajorVersion = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwMinorVersion = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwBuildNumber = PeekInt (thebank,nextOffset%) nextOffset%=nextOffset%+4 dwPlatformId = PeekInt (thebank,nextOffset%) If (dwBuildNumber And $FFFF) > $7FFF BuildNr = (dwBuildNumber And $FFFF) - $10000 Else BuildNr = dwBuildNumber And $FFFF End If OSString$=ResolveOSName$(dwPlatformId,dwMajorVersion,dwMinorVersion,dwBuildNumber) FreeBank theBank FreeBank szCSDVersion_ Return OSString$ End Function Function AddressOf(Bank) ; Find the correct Adress of a Bank (for C *Pointer) Local Address = CreateBank(4) api_RtlMoveMemory(Address,Bank+4,4) Return PeekInt(Address,0) End Function Function string_in_bank(s$,bankhandle) ; Put a String in a Bank Local pos=1 Local pos2=0 Repeat PokeByte(bankhandle,pos2,Asc(Mid(s$,pos,Len(s$)))) pos=pos+1 pos2=pos2+1 Until pos=Len(s$)+1 End Function Function bank_in_string$(bankhandle) ; Get a String from a Bank Local s$="" Local pos=0 Repeat s$=s$+Chr(PeekByte(bankhandle,pos)) pos=pos+1 Until pos=BankSize(bankhandle) s$=Replace$(s$,Chr(0)," ") Return s$ End Function Function ResolveOSName$(Platform,Major,Minor,Build) Local ReturnString$="Unknown Operating System" If Platform = VER_PLATFORM_WIN32_NT Select Major Case 4 ReturnString$ = "Windows NT" Case 5 If (Minor = 0) ReturnString$ = "Windows 2000" Else If (Minor = 1) ReturnString = "Windows XP" End If EndIf Case 6 If (Minor = 0 ) ReturnString$ = "Windows Vista" Else If (Minor = 1) ReturnString = "Windows7" EndIf EndIf End Select Else If Platform = VER_PLATFORM_WIN32_WINDOWS If (Major > 4) If Build = 1998 ReturnString$ = "Windows 98" Else ReturnString$ = "Windows 98 SE" EndIf Else If (Major = 4) If (Minor = 0) ReturnString$ = "Windows 95" Else If (Minor=10) If Build = 1998 ReturnString$ = "Windows 98" Else ReturnString$ = "Windows 98 SE" End If Else If (Minor = 90) ReturnString$ = "Windows ME" End If End If End If End If End If End If End If ReturnString$ = ReturnString$+" Version "+Str(Major)+"."+Str(Minor)+" ( Build: "+Str(Build)+")" Return ReturnString$ End Function |
| ||
Here's one more update, to include windows 7, windows 8, and windows 8.1. Bank version only. needs two files: /userlibs/kernel32.decls containing: .lib "kernel32.dll" api_GetVersionEx% (lpVersionInformation*) : "GetVersionExA" api_RtlMoveMemory(Destination*,Source,Length) : "RtlMoveMemory" /userlibs/comdlg32.decls containing: .lib "comdlg32.dll" api_GetOpenFileName% (pOpenfilename*) : "GetOpenFileNameA" api_GetSaveFileName% (pOpenfilename*) : "GetSaveFileNameA" |
| ||
Don't trust GetVersion() If the User sets the compatibility mode to XP then GetVersion will show the numbers for XP on a Win 8 or Win 7 System And if the compatibility is set, even if you replace the file with a newer version - its still set to compatibility. You have to reset compatibility by hand as you set it before you start the program which uses GetVersion() . |
| ||
Yes, even registry checks return compatibility versions for later OS using Compatibility Mode. |
| ||
What about OLDER versions of windows? XD |
| ||
What about OLDER versions of windows? XD Given the blitzmax won't run on anything older than windows 95, the code wouldn't work in the first place. :-? |
| ||
This is great code, just what I was pondering over, thanks. |
| ||
Any update on Windows 10 detection? |
Code Archives Forum