Page 1 of 1

Posted: Mon Oct 29, 2001 3:05 am
by BackupUser
Restored from previous forum. Originally posted by PB.

First: Sorry about the lack of indentation, but I don't know how to turn HTML on and the FAQ doesn't say how either...

Anyway, can anyone help me with the problem of determing which Operating System my app is running on? Here's some code that VB uses to find it, by using the SysInfo control (I think), and a PureBasic equivalent would be great (including Windows XP too, unlike this example). Thanks!

BTW, please don't direct me to the Win32 API guide -- I've tried to work it out but can't. An actual working example would be preferred. :)

With osinfo
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
getVersion = "Win95"
Case 10
getVersion = "Win98"
Case 90
getVersion = "WinME"
Case Else
getVersion = "Failed"
End Select
Case 2
Select Case .dwMajorVersion
Case 3
getVersion = "NT_3.51"
Case 4
getVersion = "NT_4.0"
Case 5
getVersion = "Win2000"
Case Else
getVersion = "Failed"
End Select
Case Else
getVersion = "Failed"
End Select
End With


Edited by - PB on 29 October 2001 03:13:11

Posted: Mon Oct 29, 2001 11:49 am
by BackupUser
Restored from previous forum. Originally posted by wavemaker.

This worked for me:

Code: Select all

lpVersionInformation.OSVERSIONINFO
lpVersionInformation\dwOSVersionInfoSize = 148
success = GetVersionEx_(@lpVersionInformation)
If success
  Select lpVersionInformation\dwPlatformId
    Case #VER_PLATFORM_WIN32s
      PlatformID$ = "Windows 3.1"
    Case #VER_PLATFORM_WIN32_WINDOWS
      PlatformID$ = "Windows 95"
    Case #VER_PLATFORM_WIN32_NT
      PlatformID$ = "Windows NT"
    Default
      PlatformID$ = "Unknown"
  EndSelect
  osVersion$ = "Version: " + Str(lpVersionInformation\dwMajorVersion) + "." + Str(lpVersionInformation\dwMinorVersion) + chr(10) + chr(13) + "Build: " + Str(lpVersionInformation\dwBuildNumber) + chr(10) + chr(13) + "Platform: " + PlatformID$ + chr(10) + chr(13) + "Other: Unavailable"; The following gives an assembly error: +PeekS(@lpVersionInformation\szCSDVersion);
Else
  osVersion$ = "Unable to retrieve OS version information."
EndIf
MessageRequester("OS version",osVersion$,0)
End
I hope it's useful.

Juan Calderón Alonso
Registered user

Posted: Mon Oct 29, 2001 12:05 pm
by BackupUser
Restored from previous forum. Originally posted by wavemaker.

Sorry, applying the constants you provide is more accurate:

Code: Select all

lpVersionInformation.OSVERSIONINFO
lpVersionInformation\dwOSVersionInfoSize = 148
success = GetVersionEx_(@lpVersionInformation)
If success
  Select lpVersionInformation\dwPlatformId
    Case #VER_PLATFORM_WIN32_WINDOWS
      Select lpVersionInformation\dwMinorVersion
        Case 0
          getVersion$ = "Windows 95"
        Case 10
          getVersion$ = "Windows 98"
        Case 90
          getVersion$ = "Windows ME"
        Default
          getVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32_NT
      Select lpVersionInformation\dwMajorVersion
        Case 3
          getVersion$ = "Windows NT 3.51"
        Case 4
          getVersion$ = "Windows NT 4.0"
        Case 5
          getVersion$ = "Windows 2000"
        Default
          getVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32s
      getVersion$ = "Windows 3.1"
    Default
      getVersion$ = "Unknown"
  EndSelect
  osVersion$ = "Platform: "+getVersion$+chr(10)+chr(13)+"Version: "+Str(lpVersionInformation\dwMajorVersion)+"."+Str(lpVersionInformation\dwMinorVersion)+chr(10)+chr(13)+"Build: "+Str(lpVersionInformation\dwBuildNumber)+chr(10)+chr(13)+"Other: Unavailable";The following gives an assembly error: +PeekS(@lpVersionInformation\szCSDVersion);
Else
  osVersion$ = "Unable to retrieve OS version information."
EndIf
MessageRequester("OS version",osVersion$,0)
End
Bye,

Juan Calderón Alonso
Registered user

Posted: Mon Oct 29, 2001 6:12 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Hi PB, try this:
PeekS(@lpVersionInformation\szCSDVersion[0])
and it will work without assembly error.


BTW: I get a wrong build number on my system.

When you look at:
All Forums -> Beginners -> Declare a size of a string
you will see another way to get Versions Info.
The Buildnumber with this method is the right one.
Hope this helps.



Have a nice day...
Franco

Posted: Mon Oct 29, 2001 7:57 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

OK here is your code running... also the build # is ok!

Code: Select all

lpVersionInformation.OSVERSIONINFO
lpVersionInformation\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
If GetVersionEx_(@lpVersionInformation)
  Select lpVersionInformation\dwPlatformId
    Case #VER_PLATFORM_WIN32_WINDOWS
      Select lpVersionInformation\dwMinorVersion
        Case 0
          GetVersion$ = "Windows 95"
        Case 10
          GetVersion$ = "Windows 98"
        Case 90
          GetVersion$ = "Windows ME"
        Default
          GetVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32_NT
      Select lpVersionInformation\dwMajorVersion
        Case 3
          GetVersion$ = "Windows NT 3.51"
        Case 4
          GetVersion$ = "Windows NT 4.0"
        Case 5
          GetVersion$ = "Windows 2000"
        Default
          GetVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32s
      GetVersion$ = "Windows 3.1"
    Default
      GetVersion$ = "Unknown"
  EndSelect
  OsVersion$ = "Platform: "+GetVersion$+chr(10)+chr(13)+"Version: "+Str(lpVersionInformation\dwMajorVersion)+"."+Str(lpVersionInformation\dwMinorVersion)+chr(10)+chr(13)+"Build: "+Str(PeekW(@lpVersionInformation\dwBuildNumber))+"."+Str(PeekW(@lpVersionInformation\dwBuildNumber+2))+chr(10)+chr(13)+"Other: "+PeekS(@lpVersionInformation\szCSDVersion[0])
Else
  OsVersion$ = "Unable to retrieve OS version information."
EndIf
  MessageRequester("OS version",OsVersion$,0)
End


Have a nice day...
Franco

Posted: Mon Oct 29, 2001 8:50 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

Thanks to all who replied -- I appreciate it! :)

BTW, someone in a VB group posted this info for Windows XP, which can worked into your code examples above: XP = dwVerMajor is 5, dwVerMinor is 1.

BTW #2: How the heck did you guys post with indentations? When I try all my text gets stripped of the leading spaces... :(

Posted: Mon Oct 29, 2001 11:42 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

You have to write it this way:

here put your comments....
[ c o d e ] <- this is the start of your code (without spaces)
your code .....
[ / c o d e ] <- this is the end of your code (without spaces)
that's it....



Have a nice day...
Franco


Edited by - franco on 29 October 2001 23:45:44

Posted: Tue Oct 30, 2001 12:30 am
by BackupUser
Restored from previous forum. Originally posted by Franco.

OK, let's complete the M$ mess, the M$ platform SDK says:

-------snip
dwBuildNumber
Windows NT/2000/XP: Identifies the build number of the operating system.
Windows 95/98/Me: Identifies the build number of the operating system in the low-order word. The high-order word contains the major and minor version numbers.
-------snip

I suppose my code (to get the correct build #) is only valid for 95/98/Me.
Windows NT/2000/XP has one long value. So you have to check for this.
Can anybody with NT/2000/XP confirm that?




Have a nice day...
Franco

Posted: Tue Oct 30, 2001 11:02 am
by BackupUser
Restored from previous forum. Originally posted by PB.
I suppose my code (to get the correct build #) is only valid for 95/98/Me.
Windows NT/2000/XP has one long value. So you have to check for this.
Can anybody with NT/2000/XP confirm that?
Your code posted above (29 October 2001, 19:57:57) works fine for me
with Windows 2000... it reports everything fine. It reports the
following:

Platform: Windows 2000
Version: 5.0
Build: 2195.0
Other: Service Pack 2

Hope this helps!

Posted: Tue Oct 30, 2001 10:18 pm
by BackupUser
Restored from previous forum. Originally posted by Mr.Skunk.

Hi,

For Windows Xp Home it displays :

Platform : windows 2000
Version 5.1
Build : 2600.0
Other :

Hope it helps...

Mr Skunk

Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st

Posted: Tue Mar 26, 2002 8:34 am
by BackupUser
Restored from previous forum. Originally posted by PB.

Code: Select all

lpVersionInformation.OSVERSIONINFO
lpVersionInformation\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
If GetVersionEx_(@lpVersionInformation)
  Select lpVersionInformation\dwPlatformId
    Case #VER_PLATFORM_WIN32_WINDOWS
      Select lpVersionInformation\dwMinorVersion
        Case 0
          GetVersion$ = "Windows 95"
        Case 10
          GetVersion$ = "Windows 98"
        Case 90
          GetVersion$ = "Windows ME"
        Default
          GetVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32_NT
      Select lpVersionInformation\dwMajorVersion
        Case 3
          GetVersion$ = "Windows NT 3.51"
        Case 4
          GetVersion$ = "Windows NT 4.0"
        Case 5
          GetVersion$ = "Windows 2000"
        Default
          GetVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32s
      GetVersion$ = "Windows 3.1"
    Default
      GetVersion$ = "Unknown"
  EndSelect
  OsVersion$ = "Platform: "+GetVersion$+chr(10)+chr(13)+"Version: "+Str(lpVersionInformation\dwMajorVersion)+"."+Str(lpVersionInformation\dwMinorVersion)+chr(10)+chr(13)+"Build: "+Str(PeekW(@lpVersionInformation\dwBuildNumber))+"."+Str(PeekW(@lpVersionInformation\dwBuildNumber+2))+chr(10)+chr(13)+"Other: "+PeekS(@lpVersionInformation\szCSDVersion[0])
Else
  OsVersion$ = "Unable to retrieve OS version information."
EndIf
  MessageRequester("OS version",OsVersion$,0)
End
Can somebody please add to this code so it detects Windows XP home and pro?
Many thanks... I think I know how to do it, but I don't have XP to test it,
so there's no point in me attempting it...

PB - Registered PureBasic Coder

Posted: Tue Mar 26, 2002 4:40 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.
Can somebody please add to this code so it detects Windows XP home and pro?
Many thanks... I think I know how to do it, but I don't have XP to test it,
so there's no point in me attempting it...
Good morning PB,
found this code on my HD at work (W98SE):

Code: Select all

 
lpVersionInformation.OSVERSIONINFO
lpVersionInformation\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
If GetVersionEx_(@lpVersionInformation)
  Select lpVersionInformation\dwPlatformId
    Case #VER_PLATFORM_WIN32s
      GetVersion$ = "Windows 3.1"
    Case #VER_PLATFORM_WIN32_WINDOWS
      Select lpVersionInformation\dwMinorVersion
        Case 0
          GetVersion$ = "Windows 95"
        Case 10
          GetVersion$ = "Windows 98"
        Case 90
          GetVersion$ = "Windows ME"
        Default
          GetVersion$ = "Unknown"
      EndSelect
    Case #VER_PLATFORM_WIN32_NT
      Select lpVersionInformation\dwMajorVersion
        Case 3
          GetVersion$ = "Windows NT 3.51"
        Case 4
          GetVersion$ = "Windows NT 4.0"
        Case 5
          Select lpVersionInformation\dwMinorVersion
            Case 0
              GetVersion$ = "Windows 2000"
            Case 1
              GetVersion$ = "Windows XP"
            Default
              GetVersion$ = "Unknown"
          EndSelect
        Default
          GetVersion$ = "Unknown"
      EndSelect
;    Case #VER_PLATFORM_WIN32_CE
;      GetVersion$ = "Windows CE"
    Default
      GetVersion$ = "Unknown"
  EndSelect
  OsVersion$ = "Platform: "+GetVersion$+Chr(10)+Chr(13)+"Version: "+Str(lpVersionInformation\dwMajorVersion)+"."+Str(lpVersionInformation\dwMinorVersion)+Chr(10)+Chr(13)+"Build: "+Str(PeekW(@lpVersionInformation\dwBuildNumber))+"."+Str(PeekW(@lpVersionInformation\dwBuildNumber+2))+Chr(10)+Chr(13)+"Other: "+PeekS(@lpVersionInformation\szCSDVersion[0])
Else
  OsVersion$ = "Unable to retrieve OS version information."
EndIf
  MessageRequester("OS version",OsVersion$,0)
End
If I recall it right, it worked on WinXP (last year at home...) also fine.
I can double check it tonight if you want
Hope this helps...


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 27 March 2002 05:10:57

Posted: Tue Mar 26, 2002 5:11 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> I can double check it tonight if you want

Yes please, that would be appreciated!

Side-note: Wow, this was my 500th post!


PB - Registered PureBasic Coder

Edited by - PB on 26 March 2002 17:13:06

Posted: Wed Mar 27, 2002 5:20 am
by BackupUser
Restored from previous forum. Originally posted by Franco.

Hi PB,
the code works fine under WinXP (please copy and paste the code now! - changed because there was a fragmented documentation line on line 18)

Under WinXP I get the result:

Platform: Windows XP
Version: 5.1
Build: 2600.0
Other:

BTW1: The empty 'Other:' line reminds me to install 2 security patches for WinXP I saw somewhere...

BTW2: Fred and PB, 500 mails but no 4th star...

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 27 March 2002 05:27:40

Posted: Wed Mar 27, 2002 9:14 am
by BackupUser
Restored from previous forum. Originally posted by PB.

> the code works fine under WinXP

Many thanks, Franco!

> BTW2: Fred and PB, 500 mails but no 4th star...

I know, what's going on?


PB - Registered PureBasic Coder