Solved

Detecting os in a word macro

Posted on 2003-11-04
5
211 Views
Last Modified: 2010-05-03
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
Comment
Question by:NeoTeq
  • 2
  • 2
5 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 50 total points
Comment Utility
See: Obtaining Windows' Version Information
http://www.mvps.org/vbnet/code/system/getversionex.htm
0
 
LVL 5

Assisted Solution

by:fantasy1001
fantasy1001 earned 50 total points
Comment Utility
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
 
LVL 10

Author Comment

by:NeoTeq
Comment Utility
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
 
LVL 5

Expert Comment

by:fantasy1001
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
>>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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now