Results 1 to 20 of 20

Thread: Determining operating system

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Central NY
    Posts
    172

    Determining operating system

    Is there a way thru VB to determine whether or not the program is running on a Win NT machine or Win 2000 machine?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Win2000 is NT - it is nothing more than NT5 with a fancier name. In fact, it started out life as NT5, and then Microsoft decided that the name needed some work. They get really ticked when that is pointed out. Notice the platform Id has not changed since NT 3.51! Try this
    VB Code:
    1. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long
    2.  
    3. Private Type OSVERSIONINFO
    4.     dwOSVersionInfoSize As Long
    5.     dwMajorVersion As Long
    6.     dwMinorVersion As Long
    7.     dwBuildNumber As Long
    8.     dwPlatformId As Long
    9.     szCSDVersion As String * 128
    10. End Type
    11.  
    12. Private Const VER_PLATFORM_WIN32s = 0
    13. Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    14. Private Const VER_PLATFORM_WIN32_NT = 2
    15.  
    16. Private Function LoWord(lngIn As Long) As Integer
    17.    If (lngIn And &HFFFF&) > &H7FFF Then
    18.       LoWord = (lngIn And &HFFFF&) - &H10000
    19.    Else
    20.       LoWord = lngIn And &HFFFF&
    21.    End If
    22. End Function
    23.  
    24. Private Function ShowWinVersion(vLabel As Label)
    25. Dim version As OSVERSIONINFO
    26. Dim strPlatform As String
    27.  
    28.     version.dwOSVersionInfoSize = Len(version)
    29.     GetVersionEx version
    30.  
    31.     If version.dwPlatformId = 1 And version.dwMinorVersion = 10 And LoWord(version.dwBuildNumber) = 1998 Then
    32.         strPlatform = "Microsoft Windows 98 "
    33.     ElseIf version.dwPlatformId = 1 And version.dwMinorVersion = 10 And LoWord(version.dwBuildNumber) = 2222 Then
    34.         strPlatform = "Microsoft Windows 98 SE "
    35.     ElseIf version.dwPlatformId = 1 And version.dwMinorVersion = 90 And LoWord(version.dwBuildNumber) = 3000 Then
    36.         strPlatform = "Microsoft Windows ME "
    37.     ElseIf version.dwPlatformId = 1 And version.dwMinorVersion = 0 And LoWord(version.dwBuildNumber) = 950 Then
    38.         strPlatform = "Microsoft Windows 95 "
    39.     ElseIf version.dwPlatformId = 1 And version.dwMinorVersion = 0 And LoWord(version.dwBuildNumber) = 1111 Then
    40.         strPlatform = "Microsoft Windows 95B "
    41.     End If
    42.            
    43.     If version.dwPlatformId = 2 And version.dwMajorVersion = 3 Then
    44.         strPlatform = "Microsoft Windows NT 3.51 "
    45.     ElseIf version.dwPlatformId = 2 And version.dwMajorVersion = 4 Then
    46.         strPlatform = "Microsoft Windows NT "
    47.     ElseIf version.dwPlatformId = 2 And version.dwMajorVersion = 5 Then
    48.         strPlatform = "Microsoft Windows 2000 "
    49.     End If
    50.    
    51.    strPlatform = strPlatform & "v" & Format(version.dwMajorVersion) & "." & _
    52.                        Format(version.dwMinorVersion) & " (Build " & LoWord(version.dwBuildNumber) & ")"
    53.    
    54.     vLabel.Alignment = 2
    55.     vLabel.BackStyle = 0
    56.     vLabel.Caption = strPlatform
    57. End Function
    58.  
    59. Private Sub Form_Load()
    60. 'Developed by amitabh
    61.     ShowWinVersion Label1
    62. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Central NY
    Posts
    172
    Thanks, I will give it a try.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2001
    Location
    Central NY
    Posts
    172
    That worked great!. It was just what I needed.

    Thanks...

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    As peet is fond of saying...


  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    What about Xp?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: As peet is fond of saying...

    Originally posted by Hack
    hmmm ... seems you say that more often than me now
    -= a peet post =-

  8. #8
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: Well

    Originally posted by James Stanich
    What about Xp?
    VB Code:
    1. Public Declare Function GetVersionExA Lib "kernel32" _
    2.                (lpVersionInformation As OSVERSIONINFO) As Integer
    3.  
    4.             Public Type OSVERSIONINFO
    5.                dwOSVersionInfoSize As Long
    6.                dwMajorVersion As Long
    7.                dwMinorVersion As Long
    8.                dwBuildNumber As Long
    9.                dwPlatformId As Long
    10.                szCSDVersion As String * 128
    11.             End Type
    12.  
    13.             Public Function getVersion() As String
    14.                Dim osinfo As OSVERSIONINFO
    15.                Dim retvalue As Integer
    16.  
    17.                osinfo.dwOSVersionInfoSize = 148
    18.                osinfo.szCSDVersion = Space$(128)
    19.                retvalue = GetVersionExA(osinfo)
    20.  
    21.                With osinfo
    22.                Select Case .dwPlatformId
    23.  
    24.                 Case 1
    25.                
    26.                     Select Case .dwMinorVersion
    27.                         Case 0
    28.                             getVersion = "Windows 95"
    29.                         Case 10
    30.                             getVersion = "Windows 98"
    31.                         Case 90
    32.                             getVersion = "Windows Mellinnium"
    33.                     End Select
    34.    
    35.                 Case 2
    36.                     Select Case .dwMajorVersion
    37.                         Case 3
    38.                             getVersion = "Windows NT 3.51"
    39.                         Case 4
    40.                             getVersion = "Windows NT 4.0"
    41.                         Case 5
    42.                             If .dwMinorVersion = 0 Then
    43.                                 getVersion = "Windows 2000"
    44.                             Else
    45.                                 getVersion = "Windows XP"
    46.                             End If
    47.                     End Select
    48.    
    49.                 Case Else
    50.                    getVersion = "Failed"
    51.             End Select
    52.  
    53.                End With
    54.             End Function
    -= a peet post =-

  9. #9
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    hmmmm .... What about Terminal Server
    -= a peet post =-

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    And Citrix Server ?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    hmm... seems we have to make some addons to these routines
    -= a peet post =-

  12. #12
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by peet
    hmm... seems we have to make some addons to these routines
    It'll work for most OS's. Just trying to give Hack a hard time...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  13. #13
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Re: Well

    Originally posted by James Stanich
    It'll work for most OS's. Just trying to give Hack a hard time...


    I would really like to detirmine if my app was running on a Terminal Server, so hopefully hack will dig into that pile of old VBP-Journals that he has in his basement, and deliver a solution before I get out of bed tomorrow morning

    night all
    -= a peet post =-

  14. #14
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    I got the solution from someone on these board a long time ago.
    I found the thread, but it looks like I am talking to myself

    here take a look James : http://www.vbforums.com/showthread.p...erminal+server

    weird
    -= a peet post =-

  15. #15
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    So where's the RyeBread code?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  16. #16
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Determining the system OS with the SysInfo control

    VB Code:
    1. Dim OS As String
    2.  
    3. With SysInfo1
    4.     Select Case .OSPlatform
    5.         Case 0: OS = "Win32"
    6.         Case 1:
    7.             Select Case .OSVersion
    8.                 Case 4: OS = "Win 95"
    9.                 Case 4.1: OS = "Win 98"
    10.             End Select
    11.         Case 2:
    12.             Select Case .OSVersion
    13.                 Case 4: OS = "Win NT"
    14.                 Case 5: OS = "Win 2000"
    15.                 Case 6: OS = "Win XP"
    16.             End Select
    17.     End Select
    18.    
    19.     MsgBox "Build:" & .OSBuild & vbNewLine & _
    20.         "Platform:" & OS & "(" & .OSPlatform & ")" & vbNewLine & _
    21.         "Version:" & .OSVersion
    22. End With

    Still no terminal server though...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  17. #17
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    TS is not an OS, thus it will not work this way, I think his answer had something to do with reading an environment setting, and from that you could determine if this was a TS or not...just cant remember what environment var to read
    Last edited by peet; Oct 19th, 2002 at 02:23 AM.
    -= a peet post =-

  18. #18
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. If Left$(Environ$("SESSIONNAME"), 3) = "RDP" Then
    2.         MsgBox "TS Detected!!"
    3.     End If

    just in case anyone else wanted this
    -= a peet post =-

  19. #19

  20. #20
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    glad you liked it

    now we just need someone with access to citrix to figure out if Left(Environ$("SESSIONNAME"), 3) = "RDP" is true or not
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width