sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- 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;
produces this;
and this;
produces this;
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?
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?