Get Operating system name

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,279
Office Version
2016
Platform
Windows
I'm trying to get the name of the Operating system, that is the simple name that most users understand, i.e Windows 7.

I've tried 2 approaches as follows;

This;

Code:
Application.OperatingSystem
produces this;

Windows (32-bit) NT 6.02
and this;

Code:
Public Function getOperatingSystem()
Dim localHost       As String
Dim objWMIService   As Variant
Dim colOperatingSystems As Variant
Dim objOperatingSystem As Variant
On Error GoTo Error_Handler
localHost = "." 'Technically could be run against remote computers, if allowed
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & localHost & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem In colOperatingSystems
getOperatingSystem = objOperatingSystem.Caption & " " & objOperatingSystem.Version
Exit Function
Next
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
MsgBox "The following error has occured." & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: getOperatingSystem" & vbCrLf & _
"Error Description: " & Err.Description, _
vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function
produces this;

Windows 10 Pro 10.0.10586
Both of these are generated on a Windows 10 system. I'm being fussy I know, but all I was expecting was simply 'Windows 10' without the extra stuff and I don't understand why the first one produces NT at all.

Is there an easy way of doing this? Or if not can I trim the 2nd one so I just get the simple version?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
11,696
Office Version
365, 2010
Platform
Windows, Mobile
Or if not can I trim the 2nd one so I just get the simple version?
Does not just changing

Code:
getOperatingSystem = objOperatingSystem.Caption & " " & objOperatingSystem.Version
to

Code:
getOperatingSystem = objOperatingSystem.Caption
Not do what you want?

Edit: and do you not have the word Microsoft in front of
Windows 10 Pro 10.0.10586
 
Last edited:

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,279
Office Version
2016
Platform
Windows
Thanks guys - both suggestions work.
 

Forum statistics

Threads
1,084,753
Messages
5,379,655
Members
401,620
Latest member
Ankur Teotia

Some videos you may like

This Week's Hot Topics

  • VBA code giving errors and stopping Excel
    Hello Experts, I have this code being used to loop through files in a file path, and copy specific data to another sheet. It is giving me several...
  • Disable MsgBox message
    Morning, I have a userform where if i leave a ComboBox empty i see a MsgBox warning me that i must enter an invoice number. It is this MsgBox i...
  • Macro Recorder into VBA, Copy Paste Data Filled Cells
    Hi Everyone, I have a macro recorder file that takes a selection of data, copies, then pastes into a new sheet on ("A2:B2") The issue is my...
  • Number format changes while pasting into a cell
    Hi, I am trying to paste a number 180204524303 from an email to an excel cell, however, whenever i try to do so , the the paste value appears as...
  • Collating data
    Hello all. Could someone please help. I am trying to pull all column data from multiple sheets (24 I total so far) into 1 master sheet without...
  • Sum Multiple Columns Based on Multiple Criteria
    I am trying to consolidate data by summing columns G through M based on material, plant, vendor, and fiscal year being identical. The period does...
Top