Results 1 to 11 of 11
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code to check the operating system (Word97/XP)

    HI - I'm sure this has been posted before...

    is there any VBA code to check what the current operating system is?

    many thanks Diana
    ps I would have done a search but its not available on this site?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to check the operating system (Word97/XP)

    Somthing like this:

    MsgBox Application.OperatingSystem
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code to check the operating system (Word97/XP)

    In Word, it's under System.OperatingSystem and System.Version; if you combine both, you probably can get what you need.

    For Windows XP, for example:

    ?system.OperatingSystem
    Windows NT
    ?system.Version
    5.1

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to check the operating system (Word97/XP)

    HI

    I've tested the code msgbox system.OperatingSystem, on the different environments

    On Windows NT 4.0 - the value returned is 'Windows NT'
    On Windows XP - the value returned is 'Windows NT'

    & I'm going to check/test on a Win2000 environment this afternoon.
    Why on a WinXP pc would the value returned be 'Windows NT'?
    It was a new pc with a new build of WinXP. it wasnt like an existing pc with WinNT 4.0 & then the same pc was upgraded to WinXP?

    Diana

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code to check the operating system (Word97/XP)

    Please read my example more carefully. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  6. #6
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to check the operating system (Word97/XP)

    ...oh ok

    for this code to return the correct values, you need the operating system and the version number therefore
    in Office97
    operating system version returns:
    windows NT windows nt 4.0
    windows XP windows nt 5.1
    windows 2000 windows nt 5.0( i'll confirm by this afternoon)

    & I believe in OfficeXP it will return the values you expect (i'll check/test this by this afternoon) eg
    operating system version returns:
    windows NT windows nt 4.0
    windows XP windows XP
    windows 2000 windows 2000( i'll confirm by this afternoon)

    is that correct? Diana : )

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: code to check the operating system (Word97/XP)

    My example was for Office XP running on Windows XP. Believe it or not, NT 5.1. (It would be pretty lousy of Office to give different answers for different versions of Office on the same OS, even if it could.)

  8. #8
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: code to check the operating system (Word97/XP)

    well we experienced the following the other day:

    in WinNT - on an application exe >we right mouse click goto properties & the Version number displayed for the application is Ver 2.0.
    on WinXP - on exactly the same (emphasise again exactly the same) application exe >we right mouse click goto properties & the Version number displayed for the application is Ver 2.1.1.

    ....I'm sure theres a logical explaination.

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: code to check the operating system (Word97/XP)

    Probably. It depends on what application executable you're looking at. There are often specific versions for different versions of Windows, even if they appear to be the "same" version of the application. You may notice on some sites that you download from a different shortcut for Windows NT than for Windows 2000/XP. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  10. #10
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: code to check the operating system (Word97/XP)

    The most reliable way to get accurate Windows Operating System (OS) version info is to use Windows GetVersionExA API function. The sample code below was adapted in part from MSKB Article 189249 HOWTO: Determine Which 32-Bit Windows Version Is Being Used. The article provides a useful table for interpreting the information returned by the OSVERSIONINFO data structure:

    <table border=1><td> </td><td>Windows 95</td><td>Windows 98</td><td>Windows Me</td><td>Windows NT 4.0</td><td>Windows 2000</td><td>Windows XP</td><td>Platform ID</td><td>1</td><td>1</td><td>1</td><td>2</td><td>2</td><td>2</td><td>Major Version</td><td>4</td><td>4</td><td>4</td><td>4</td><td>5</td><td>5</td><td>Minor Version</td><td>0</td><td>10</td><td>90</td><td>0</td><td>0</td><td>1</td>
    </table>

    Sample code:

    Option Explicit

    Private Declare Function GetVersionEx Lib "Kernel32" _
    Alias "GetVersionExA" (lpVersInfo As OSVERSIONINFO) As Boolean

    Public Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
    End Type

    Public Function GetOSVersion() As String

    Dim osinfo As OSVERSIONINFO
    Dim intRtnVal As Integer
    Dim strVersName As String
    Dim strVersNo As String
    Dim strBuildNo As String

    osinfo.dwOSVersionInfoSize = 148
    osinfo.szCSDVersion = Space$(128)
    intRtnVal = GetVersionEx(osinfo)

    With osinfo
    Select Case .dwPlatformId
    Case 1 ' WIN 95
    Select Case .dwMinorVersion
    Case 0
    strVersName = "Windows 95"
    Case 10
    strVersName = "Windows 98"
    Case 90
    strVersName = "Windows ME"
    End Select

    Case 2 ' WIN NT
    Select Case .dwMajorVersion
    Case 3
    strVersName = "Windows NT 3.51"
    Case 4
    strVersName = "Windows NT 4.0"
    Case 5
    If .dwMinorVersion = 0 Then
    strVersName = "Windows 2000"
    ElseIf .dwMinorVersion = 1 Then
    strVersName = "Windows XP"
    End If
    End Select

    strVersNo = .dwMajorVersion & "." & .dwMinorVersion
    ' Get just the low word of the result for Build No:
    strBuildNo = "Build " & CStr(.dwBuildNumber And &HFFFF&)
    GetOSVersion = strVersName & " " & strVersNo & " " & strBuildNo

    Case Else
    GetOSVersion = "OS Not Available"
    End Select
    End With

    End Function

    The function above can be modified for your purposes. For example, you may have no need for the Build number. Example of use on Win XP system:

    ? GetOSVersion
    Windows XP 5.1 Build 2600

    HTH

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: code to check the operating system (Word97/XP)

    Yes, we use that approach in the diagnostics we put into our applications. It helps a lot to be able to tell which operating system they are using when they report problems with our software, and we long ago went to the 32-bit API calls for this, since all three versions of Windows NT/2000/XP will return "Windows NT" otherwise..
    Charlotte

Posting Permissions

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