Detecting Windows Version?
BlitzPlus Forums/BlitzPlus Programming/Detecting Windows Version?
| ||
You clever API guys have a solution to this, I just know it :) How can I get Blitz+ to poll the name of the OS (or anything that would allow me to denote what OS the program is running on)? I basically need to know if the program is being run on Win9x or WinNT kernals (don't ask why - long story). Anywone help a brutha out? THANKS! |
| ||
Doing a little research, I figure out that I can use the API by adding some Kernel32 libs action: .lib "Kernel32.dll" GetVersion%():"GetVersion" Now, if I call that, I get a nice long number, but have NO idea how to get what I need out of that number. Here is the API info I looked at: http://leb.net/wine/WinDoc/msdn/sdk/platforms/doc/sdk/win32/func/src/f42_7.htm ZERO idea how to turn that number into something useful. I ran it on Win98 and got a NEGATIVE number, but a positive on WinXP. Any help, much appreciated! |
| ||
James Boyd wrote a userlib some time ago for this, I think.... |
| ||
Hi Shane, Here's a good way: ; Userlib declaration .lib "Kernel32.dll" GetVersionEx%(VersionInfo*):"GetVersionExA" ; Blitz code for querying platform Version = CreateBank(148) PokeInt(Version, 0, BankSize(Version)) If GetVersionEx(Version) Then Select PeekInt(Version, 16) Case 0 : Notify "You are running Windows 3.1" Case 1 : Notify "You are running on the Windows 9x kernel" Case 2 : Notify "You are running on the Windows NT kernel" Default : Notify "Unexpected value for Platform ID.", True End Select Else Notify "There was an error querying version info.", True EndIf For info, see here: GetVersionEx and here: OSVERSIONINFO data structure Ask away if you have any questions. =) |
| ||
Thanks a bunch ... You know, its been a long time since I've been a real active participant in the Blitz community (long live Blitz Basement, ya?) but I still find it AMAZING that the community still owns after all this time and hasn't self-destructed or gone the way of "those other languages". Its always a pleasure to pop back in here ... and as always the answers are groovy. Thanks guys! |
| ||
I'm glad you've returned and found it to your liking. I've only been around here for half a year, or so, though, so I'm still a newbie in comparison to many. |
| ||
Oh, I think parts of this community self-destruct from time to time, but we always seem to pull back together, like so many little pieces of the Terminator =] |
| ||
Here is more Windows information. It's essentially the same as Soja's with more fruity bits: BTW Shane, love your WinXP tips! ; Operating System Information ; userlibs ; ****************************** ; .lib "Kernel32.dll" ; GetSystemInfo%(infoPTR*):"GetSystemInfo" ; GetVersionEx%(versioninfoPTR*):"GetVersionExA" ; ****************************** Const PROCESSOR_ARCHITECTURE_ALPHA = 2 Const PROCESSOR_ARCHITECTURE_INTEL = 0 Const PROCESSOR_ARCHITECTURE_MIPS = 1 Const PROCESSOR_ARCHITECTURE_PPC = 3 Const PROCESSOR_ARCHITECTURE_UNKNOWN = $FFFF Const PROCESSOR_INTEL_386 = 386 Const PROCESSOR_INTEL_486 = 486 Const PROCESSOR_INTEL_PENTIUM = 586 Const PROCESSOR_INTEL_PENTIUM2 = 686 Const PROCESSOR_INTEL_PENTIUM3 = 786 Const PROCESSOR_MIPS_R4000 = 4000 Const VER_PLATFORM_WIN32_NT = 2 Const VER_PLATFORM_WIN32_WINDOWS = 1 Type SYSinfoType Field wProcessorArchitecture% Field wReserved% Field dwPageSize% Field lpMinimumApplicationAddress% Field lpMaximumApplicationAddress% Field dwActiveProcessorMask% Field dwNumberOfProcessors% Field dwProcessorType% Field dwAllocationGranularity% Field wProcessorLevel% Field wProcessorRevision% End Type sys.SYSinfoType=New SYSinfoType Type OSinfoType Field OSVersionInfoSize% Field MajorVersion% Field MinorVersion% Field BuildNumber% Field PlatformId% Field CSDVersion$ ; 128 in length End Type os.OSinfoType=New OSinfoType os\OSVersionInfoSize=128+20 GetVersionEx(os.OSinfoType) GetSystemInfo(sys.SYSinfoType) rev=sys\wProcessorRevision ; TEMP Print "processer architech "+sys\wProcessorArchitecture% Print "reserved "+sys\wReserved% Print "pagesize "+sys\dwPageSize% Print "min app addr "+sys\lpMinimumApplicationAddress% Print "max app addr "+sys\lpMaximumApplicationAddress% Print "processor mask "+sys\dwActiveProcessorMask% Print "num processors "+sys\dwNumberOfProcessors% Print "processor type "+sys\dwProcessorType% Print "allocg "+sys\dwAllocationGranularity% Print "processor level "+sys\wProcessorLevel% Print "processor revision "+sys\wProcessorRevision% Print "" ; operating system information osname$="?" Select os\PlatformId Case 0 : osname$="Windows 32s " Case VER_PLATFORM_WIN32_WINDOWS osname$="Windows 95" If os\MinorVersion>=10 osname$="Windows 98" Case VER_PLATFORM_WIN32_NT osname$="Windows NT " End Select Print "Operating System: "+osname$ Print " Version: "+ Str$(os\MajorVersion)+"."+Str$(os\MinorVersion) Print " Build: "+Str$(os\BuildNumber) Print " CSD Version: "+os\CSDVersion ; system processor details Select sys\wProcessorArchitecture Case PROCESSOR_ARCHITECTURE_INTEL ; Intel Select os\PlatformId Case VER_PLATFORM_WIN32_NT Select sys\wProcessorLevel Case 3 procname$="Intel 80386" If (rev And $FF00) = $FF00 procname$=procname$ + " Model " + Str$(((rev And $F0)/$F)-10) + " Stepping " + Str$((rev And $F)) Else procname$=procname$ + " Stepping " + Chr$(Asc("A") + Str$((rev And $FF)/$FF)) + " Stepping " + Str$((rev And $FF)) End If Case 4 procname$="Intel 80486" If (rev And $FF00) = $FF00 procname$=procname$ + " Model " + Str$(((rev And $F0) / $F) - 10) + " Stepping " + Str$((rev And $F)) Else procname$=procname$ + " Stepping " + Chr$(Asc("A")) + Str$((rev And $FF)/$FF) + " Stepping " + Str$(rev And $FF) End If Case 5 procname$ = "Pentium Model " + Str$((rev And $FF00)/$FF) + " Stepping " + Str$((rev And $FF)) Case 6 procname$ = "Pentium II Model " + Str$ ((rev And $FF00)/$FF) + " Stepping " + Str$((rev And $FF)) Case 7 procname$ = "Pentium III Model " + Str$ ((rev And $FF00)/$FF) + " Stepping " + Str$((rev And $FF)) End Select Case VER_PLATFORM_WIN32_WINDOWS Select sys\dwProcessorType Case PROCESSOR_INTEL_386 : procname$ = "Intel 80386" Case PROCESSOR_INTEL_486 : procname$ = "Intel 80486" Case PROCESSOR_INTEL_PENTIUM : procname$ = "Pentium" Case PROCESSOR_INTEL_PENTIUM2 : procname$ = "Pentium II" Case PROCESSOR_INTEL_PENTIUM3 : procname$ = "Pentium III" End Select End Select ; MIPS Architecture (only For WinNT) Case PROCESSOR_ARCHITECTURE_MIPS procname$ = "MIPS R" + sys\wProcessorLevel + "000" ; ALPHA Architecture (only For WinNT) Case PROCESSOR_ARCHITECTURE_ALPHA procname$ = "Alpha " + sys\wProcessorLevel + " Model A" + Str$((rev And $FF00)/$FF) + " Pass " + Str$((rev And $FF)) ; PPC Architecture (only For WinNT) Case PROCESSOR_ARCHITECTURE_PPC Select sys\wProcessorLevel Case 1, 3, 4, 20 procname$ = "PPC 6" + Right$(String$("0",16)+Str$(sys\wProcessorLevel),2) Case 6 procname$ = "PPC 603+" Case 9 procname$ = "PPC 604+" End Select procname$ = procname$ + " Processor Version " + Str$((rev And $FF00)/$FF) + "." + Str$((rev And $FF)) End Select Print procname$ Print " ----------------------------------" a$=Input$("Press RETURN to end ...") End |
| ||
Wow, thanks for all the extras! I really appreciate the support! Glad you like the XP tips... :) |
| ||
Don't forget to addGetSystemInfo(SystemInfo*):"GetSystemInfo" to your kernel32 decls file to get that to work. @SyntaxError: I notice you use a string field in the OS type to match the char* in the C struct. How do you get it to work? Whenever I try to use strings as "get" members within structs, it crashes or doesn't work quite right. I assumed it had to do with the different ways the data is stored between languages. Anyway, that's why I use banks when string data is involved. What do you think? |
| ||
Don't forget to add GettSystemInfo(SystemInfo*):"GetSystemInfo" Oops, updated. I notice you use a string field in the OS type to match the char* in the C struct. How do you get it to work? I don't know whether this actually works. At the moment I get an empty string. It should return stuff like:'Service Pack 1' if installed on WinXP 'A' for Win98SE 'C' for Win95 OSR2 That's why I use banks when string data is involved. What do you think? Yep. I switched something over before to use banks. Then, I used a PeekString$ function to get at the string. |