I’ve previously touched upon this subject back in 2016 in my post entitled VBA – Determine the Installed OS.
That said, today, I thought I’d demonstrate 2 possible approaches to retrieving Windows OS information using:
- PowerShell via VBA
- Plain VBA
and dig in a little more into the subject to show various functions that can be used and how they compare to one another at the end of the day.
In both instances, we are calling WMI to get system information. In this instance, we can get Windows OS information by querying the Win32_OperatingSystem class as it exposes a whole slew of OS properties, such as:
| Property |
Example of returned Value |
Comment |
| Caption |
Microsoft Windows 10 Home |
There is also a Name property but include Harddrive info for example ‘Microsoft Windows 10 Home|C:\WINDOWS|\Device\Harddisk0\Partition2’, so IMHO Caption is what most peopl would be considered the name. |
| OSArchitecture |
64-bit |
|
| Version |
10.0.19043 |
|
| BuildNumber |
19043 |
|
| OSLanguage |
1033 |
|
| WindowsDirectory |
C:\WINDOWS |
|
Check the official documentation, a link is provided below, for a complete listing of all the available properties.
Why?
Some people have asked me why we would need to gather such information. The reason is quite simple, this information can be useful when providing support to end-users and can assist in troubleshooting and isolating environment issues. I typically include this information as part of my error logging routine.
It makes sense to have this automatically retrieved through your application were it could be copy/paste, automatically e-mailed, … so your end-users don’t need to find a way to locate the information themselves. We always need to remember that not everyone is comfortable with computers and if we can simplify things for our end-users, we should take the opportunity to do so!
Retrieving Windows OS Information Using PowerShell
Since I’ve been doing a lot of work exploring extending VBA’s capabilities by using PowerShell through VBA, I thought it natural to see if such information could easily be accessed. As with my other VBA/PowerShell posts, such information is very easily retrieved.
These PowerShell functions all require a copy of my PS_GetOutput function which can be found in my post VBA – Run PowerShell Command.
So let’s explore how we can retrieve each property individually and then how we can get them all in a single call.
Continue reading →