Bios class, you can retrieve the current version string and compare it against a known baseline or target version to determine if an update is necessary.
Understanding the WMIC Utility
The primary tool for this task on Windows systems is wmic. This command-line interface allows administrators to query system management information directly from the operating system without requiring third-party software. The specific query we need targets the Bios instance within the root\cimv2 namespace.
To begin, open a Command Prompt window with administrative privileges. While standard user permissions often suffice for reading BIOS information, running as an administrator ensures there are no permission errors that might interrupt the script execution. Type cmd in the start menu search bar, right-click the result, and select "Run as administrator" to proceed.
Extracting the Current BIOS Version
The core command to retrieve the BIOS version is simple but requires careful syntax to ensure clean output for comparison. The following command queries the Bios class and selects only the Version property:
wmic bios get version /value
This command returns output similar to the following:
Version=1.0.0
Alternatively, using the /format:list parameter provides a more structured list format which can be easier to parse in certain scripting contexts. However, for simple version checking, the /value switch is sufficient because it isolates the key-value pair, making it easy to strip the label and keep only the version number.
Creating the Comparison Logic
Once you have the current version stored in a variable, you can compare it against a desired version. In batch scripting, string comparison is case-sensitive and exact. If your BIOS version string includes prefixes like "American Megatrends Inc.", you must account for those characters in your comparison logic.
Here is a basic example of how to structure the comparison. We will assume the target version is 1.0.0 and the current version is retrieved into the variable %BIOS_VER%.
@echo off
setlocal enabledelayedexpansion
:: Define the target version
set TARGET_VERSION=1.0.0
:: Get the current BIOS version
for /f "tokens=2 delims==" %%a in ('wmic bios get version /value') do set BIOS_VER=%%a
:: Remove any leading/trailing spaces
set BIOS_VER=%BIOS_VER: =%
:: Compare versions
if "%BIOS_VER%"=="%TARGET_VERSION%" (
echo BIOS is up to date.
) else (
echo BIOS needs update. Current: %BIOS_VER%, Target: %TARGET_VERSION%
)
In this script, the for /f loop parses the output of the wmic command. The tokens=2 delims== argument tells the parser to split the line by the equals sign and take the second part, which is the actual version string. This effectively removes the Version= prefix.
Handling Version Number Formats
It is important to note that batch files perform string comparisons, not numerical comparisons. If your BIOS versions are formatted as 1.10 and 1.2, a direct string comparison will incorrectly identify 1.10 as newer than 1.2 because '1' comes before '2' in ASCII ordering. For complex versioning schemes, consider using PowerShell instead, which has native support for version object comparison. However, for simple major.minor.patch formats where numbers are zero-padded or consistent in length, string comparison works reliably.
Automating the Process
To make this solution practical for regular maintenance, save the script as check_bios.bat. You can schedule this task using Windows Task Scheduler to run weekly or monthly. This ensures that IT departments or individual users are alerted whenever a new BIOS release is available without manual intervention.
If you need to integrate this check into a larger deployment workflow, you can modify the else block to trigger a download or notify a remote server. For example, you could append the current version and timestamp to a log file located on a network share.
echo %DATE% %TIME% - Current: %BIOS_VER% >> \\server\logs\bios_check.log
This logging capability helps maintain an audit trail of hardware states across multiple machines. It is particularly useful when managing fleets of devices where BIOS updates might introduce compatibility issues with existing drivers or firmware components.
Alternative Methods
While batch files are widely supported, PowerShell offers a more modern approach. Using Get-CimInstance Win32_BIOS provides richer data including manufacturer, release date, and SMBIOS version. This can be useful if you need to correlate BIOS releases with specific hardware revisions.
For those who prefer GUI-based solutions, many motherboard manufacturers provide their own utilities that scan the system and compare against online databases. However, these tools often require internet access and may install additional background services. The batch method remains lightweight and does not require external dependencies beyond the built-in Windows OS components.
Frequently Asked Questions
Can I use this method on Linux or macOS?
No, the wmic command is specific to Windows. On Linux, you would use dmidecode -t bios to extract similar information, while macOS uses system_profiler SPHardwareDataType. Each operating system has its own proprietary commands for accessing UEFI/BIOS metadata.
What if the BIOS version contains special characters?
If the version string includes spaces or special symbols, the parsing logic in the batch file must be adjusted. You may need to use additional string manipulation commands to trim whitespace or replace characters before performing the comparison to ensure accuracy.
Is it safe to run this script on any Windows machine?
Yes, reading the BIOS version is a read-only operation and poses no risk to your hardware or data. It does not modify any settings or flash the firmware. It is completely safe to run on production servers and workstations alike.
How do I handle different BIOS naming conventions?
Different manufacturers may format version strings differently. You should test the wmic output on each unique hardware model to understand the exact string format. Adjust the TARGET_VERSION variable in your script to match the exact output returned by the command for that specific model.
Can I automate the BIOS update after detecting a mismatch?
Automating the actual flashing process is risky and generally not recommended via simple scripts due to the high stakes of power failure during update. Instead, use the script to alert administrators who can then manually initiate the update using vendor-provided tools that include safety checks.