Excel vba to get Version of OS on computer

Biz

Well-known Member
Joined
May 18, 2009
Messages
1,773
Office Version
  1. 2021
Platform
  1. Windows
Dear All,

How can I get access to Control Panel-> Systems so I can get which version of Windows used using Excel vba?

Kind Regards,

Biz
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I wanted to know if OS was Windows XP or Windows 7.

I have found another way to do this. If someone has better method please
let me know

Code:
Sub Test()
    Dim objWMI As Object
    Dim OSs As Object
    Dim OS As Object
    Dim t As String
    Set objWMI = GetWMIService
    Set OSs = objWMI.ExecQuery("Select * from Win32_OperatingSystem")
    
    With Sheets(1)
        For Each OS In OSs
            Cells(1, 1) = "BootDevice :"
            Cells(1, 2) = OS.BootDevice
            Cells(2, 1) = "BuildNumber :"
            Cells(2, 2) = OS.BuildNumber
            Cells(3, 1) = "BuildType :"
            Cells(3, 2) = OS.BuildType
            Cells(4, 1) = "OS.Caption :"
            Cells(4, 2) = OS.Caption
            t = OS.Caption
            Debug.Print OS.CodeSet
            Debug.Print OS.CountryCode
            Debug.Print OS.CreationClassName
            Debug.Print OS.CSCreationClassName
            Debug.Print OS.CSDVersion
            Debug.Print OS.CSName
            Debug.Print OS.CurrentTimeZone
            Debug.Print OS.DataExecutionPrevention_Available
            Debug.Print OS.DataExecutionPrevention_32BitApplications
            Debug.Print OS.DataExecutionPrevention_Drivers
            Debug.Print OS.DataExecutionPrevention_SupportPolicy
            Debug.Print OS.Debug
            Debug.Print OS.Description
            Debug.Print OS.Distributed
            Debug.Print OS.EncryptionLevel
            Debug.Print OS.ForegroundApplicationBoost
            Debug.Print OS.FreePhysicalMemory
            Debug.Print OS.FreeSpaceInPagingFiles
            Debug.Print OS.FreeVirtualMemory
            Debug.Print OS.InstallDate
            Debug.Print OS.LargeSystemCache
            Debug.Print OS.LastBootUpTime
            Debug.Print OS.LocalDateTime
            Debug.Print OS.Locale
            Debug.Print OS.Manufacturer
            Debug.Print OS.MaxNumberOfProcesses
            Debug.Print OS.MaxProcessMemorySize
            'Debug.Print OS.MUILanguages ' not supported by Windows XP
            Debug.Print OS.Name
            Debug.Print OS.NumberOfLicensedUsers
            Debug.Print OS.NumberOfProcesses
            Debug.Print OS.NumberOfUsers
            'Debug.Print OS.OperatingSystemSKU ' not supported by Windows XP
            Debug.Print OS.Organization
            'Debug.Print OS.OSArchitecture ' not supported by Windows XP
            Debug.Print OS.OSLanguage
            Debug.Print OS.OSProductSuite
            Debug.Print OS.OSType
            Debug.Print OS.OtherTypeDescription
            'Debug.Print OS.PAEEnabled ' not supported by Windows XP
            Debug.Print OS.PlusProductID
            Debug.Print OS.PlusVersionNumber
            Debug.Print OS.Primary
            Debug.Print OS.ProductType
            Debug.Print OS.RegisteredUser
            Debug.Print OS.SerialNumber
            Debug.Print OS.ServicePackMajorVersion
            Debug.Print OS.ServicePackMinorVersion
            Debug.Print OS.SizeStoredInPagingFiles
            Debug.Print OS.Status
            Debug.Print OS.SuiteMask
            Debug.Print OS.SystemDevice
            Debug.Print OS.SystemDirectory
            Debug.Print OS.SystemDrive
            Debug.Print OS.TotalSwapSpaceSize
            Debug.Print OS.TotalVirtualMemorySize
            Debug.Print OS.TotalVisibleMemorySize
            Debug.Print OS.Version
            Debug.Print OS.WindowsDirectory
        Next OS
    End With
    MsgBox t, vbInformation
    If t Like "*Microsoft Windows XP*" Then
        Sheets("XP Pro").Activate
    Else
        Sheets("WIN 7").Activate
    End If
End Sub

Biz
 
Upvote 0
As a matter of interest, why does your code need to know?
 
Upvote 0
I am using vba to get meta data of files in windows xp or Windows Win 7. Instead of having two versions I thought if I can get OS then I can lookup meta data XP Pro or Win 7 using lookup. Win 7 code works even Win 8.
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,424
Members
448,896
Latest member
MadMarty

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top