Excel VBA Tools from Andrew
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: Excel vba to get Version of OS on computer

  1. #1
    Board Regular
    Join Date
    May 2009
    Location
    Perth, Australia
    Posts
    1,638
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Excel vba to get Version of OS on computer

    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

  2. #2
    MrExcel MVP AlphaFrog's Avatar
    Join Date
    Sep 2009
    Posts
    15,734
    Post Thanks / Like
    Mentioned
    8 Post(s)
    Tagged
    4 Thread(s)

    Default Re: Excel vba to get Version of OS on computer

    Try this...


    MsgBox "Microsoft Excel is using " & Application.OperatingSystem

    OperatingSystem Property [Excel 2003 VBA Language Reference]
    Paste your Excel data to the forum...
    MrExcel HTML Maker or Excel Jeanie

    How to post your vba code
    [CODE]your VBA code here[/CODE]
    The # button in the forum's editor will apply CODE tags around your selected text.

  3. #3
    Board Regular
    Join Date
    May 2009
    Location
    Perth, Australia
    Posts
    1,638
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel vba to get Version of OS on computer

    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

  4. #4
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    UK
    Posts
    31,383
    Post Thanks / Like
    Mentioned
    14 Post(s)
    Tagged
    2 Thread(s)

    Default Re: Excel vba to get Version of OS on computer

    As a matter of interest, why does your code need to know?

  5. #5
    Board Regular
    Join Date
    May 2009
    Location
    Perth, Australia
    Posts
    1,638
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Excel vba to get Version of OS on computer

    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.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

DMCA.com