Solved

Detecting os in a word macro

Posted on 2003-11-04
5
212 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
ID: 9677247
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
ID: 9677263
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
ID: 9677349
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
ID: 9677365
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
ID: 9677420
>>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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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