Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Detecting os in a word macro

Well I guess the title says it all, how do I detect the operating system (either Win98, Win2000 or WinXP) in vba?

Doesn't seem like a difficult question but if it is I'll upgrade the points.

TIA

-Neo
0
NeoTeq
Asked:
NeoTeq
  • 2
  • 2
2 Solutions
 
Ryan ChongCommented:
See: Obtaining Windows' Version Information
http://www.mvps.org/vbnet/code/system/getversionex.htm
0
 
fantasy1001Commented:
Try this: run the macro windowtype:

Option Explicit

Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

'windows-defined type OSVERSIONINFO
Public Type OSVERSIONINFO
  OSVSize         As Long         'size, in bytes, of this data structure
  dwVerMajor      As Long         'ie NT 3.51, dwVerMajor = 3; NT 4.0, dwVerMajor = 4.
  dwVerMinor      As Long         'ie NT 3.51, dwVerMinor = 51; NT 4.0, dwVerMinor= 0.
  dwBuildNumber   As Long         'NT: build number of the OS
                                  'Win9x: build number of the OS in low-order word.
                                  '       High-order word contains major & minor ver nos.
  PlatformID      As Long         'Identifies the operating system platform.
  szCSDVersion    As String * 128 'NT: string, such as "Service Pack 3"
                                  'Win9x: 'arbitrary additional information'
End Type

'my type for holding the retrieved info
Public Type RGB_WINVER
  PlatformID      As Long
  VersionName     As String
  VersionNo       As String
  ServicePack     As String
  BuildNo         As String
End Type

Public Declare Function GetVersionEx Lib "kernel32" _
   Alias "GetVersionExA" _
  (lpVersionInformation As OSVERSIONINFO) As Long


Public Function GetWinVersion(WIN As RGB_WINVER) As String

'returns a structure (RGB_WINVER)
'filled with OS information

  #If Win32 Then
 
   Dim OSV As OSVERSIONINFO
   Dim pos As Integer
   Dim sVer As String
   Dim sBuild As String
   
   OSV.OSVSize = Len(OSV)
   
   If GetVersionEx(OSV) = 1 Then
   
     'PlatformId contains a value representing the OS
      WIN.PlatformID = OSV.PlatformID
     
      Select Case OSV.PlatformID
         Case VER_PLATFORM_WIN32s:   WIN.VersionName = "Win32s"
         Case VER_PLATFORM_WIN32_NT: WIN.VersionName = "Windows NT"
         
         Select Case OSV.dwVerMajor
            Case 4:  WIN.VersionName = "Windows NT"
            Case 5:
            Select Case OSV.dwVerMinor
               Case 0:  WIN.VersionName = "Windows 2000"
               Case 1:  WIN.VersionName = "Windows XP"
            End Select
        End Select
                 
         Case VER_PLATFORM_WIN32_WINDOWS:
         
          'The dwVerMinor bit tells if its 95 or 98.
            Select Case OSV.dwVerMinor
               Case 0:    WIN.VersionName = "Windows 95"
               Case 90:   WIN.VersionName = "Windows ME"
               Case Else: WIN.VersionName = "Windows 98"
            End Select
         
      End Select

   End If
   
  #Else
 
    'can only return that this does not
    'support the 32 bit call, so must be Win3x
     WIN.VersionName = "Windows 3.x"
  #End If
 
End Function

Public Function GetWinVer() As String

'returns a string representing the version,
'ie "95", "98", "NT4", "WinXP"

  #If Win32 Then
 
   Dim OSV As OSVERSIONINFO
   Dim r As Long
   Dim pos As Integer
   Dim sVer As String
   Dim sBuild As String
   
   OSV.OSVSize = Len(OSV)
   
   If GetVersionEx(OSV) = 1 Then
   
     'PlatformId contains a value representing the OS
      Select Case OSV.PlatformID
         Case VER_PLATFORM_WIN32s: GetWinVer = "32s"
         Case VER_PLATFORM_WIN32_NT:
                   
           'dwVerMajor = NT version.
           'dwVerMinor = minor version
            Select Case OSV.dwVerMajor
               Case 3:
               
                  Select Case OSV.dwVerMinor
                     Case 0:  GetWinVer = "NT3"
                     Case 1:  GetWinVer = "NT3.1"
                     Case 5:  GetWinVer = "NT3.5"
                     Case 51: GetWinVer = "NT3.51"
                  End Select
           
               Case 4: GetWinVer = "NT 4"
               Case 5:
               
                  Select Case OSV.dwVerMinor
                     Case 0:  GetWinVer = "Win2000"
                     Case 1:  GetWinVer = "WinXP"
                  End Select
           
            End Select
         
         Case VER_PLATFORM_WIN32_WINDOWS:
         
           'dwVerMinor bit tells if its 95 or 98.
            Select Case OSV.dwVerMinor
               Case 0:    GetWinVer = "95"
               Case 90:   GetWinVer = "ME"
               Case Else: GetWinVer = "98"
            End Select
         
      End Select
         
   End If

  #Else
 
    'can only return that this does not
    'support the 32 bit call, so must be Win3x
     GetWinVer = "3x"
  #End If

End Function

Sub windowtype()
'
' windowtype Macro
' Macro created 11/4/2003 by Lim, Chin Wah
'
    Dim mywin As RGB_WINVER
    Call GetWinVersion(mywin)
    MsgBox mywin.VersionName
End Sub
0
 
NeoTeqAuthor Commented:
Well you both posted the same answer right after eachother... How am I supposed to divide points now? (The answer was great BTW, thanks!!!)

-Neo
0
 
fantasy1001Commented:
I realize one thing with this site, the more comment in a post, the more points wil go to the answer. Is it correct?

~ fantasy ~
0
 
Ryan ChongCommented:
>>I realize one thing with this site, the more comment in a post, the more points wil go to the answer. Is it correct?
It's absolutely incorrect, it will depends on how the questioner evaluates the user's comments, from there the questioner can decide how many points he/she want to split among the users. It's not a measurement in the length of the comment, but the value of the comment.

cheers ;-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now