Get Operating system name

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,340
Office Version
  1. 2016
Platform
  1. 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?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,036
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. 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,340
Office Version
  1. 2016
Platform
  1. Windows
Thanks guys - both suggestions work.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,316
Messages
5,635,521
Members
416,862
Latest member
MGDlite

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
Top