BAT script: Obtain the main hardware configuration information of the computer with one click and automatically generate a record file¶
Original link: https://www.itylq.com/bat-pc-hardware-info.html
Release date: 2022-09-19 Migration time: 2026-03-21
Recently, I encountered an enterprise with a very poor IT foundation. IT asset management, IP-Mac binding, etc. were not done at all. It was as big as an ox. It is still easy to obtain IP and Mac address information using a LAN scanning tool, but how to bind it to employee information? There is no AD domain deployed and no desktop management software installed. It is impossible to push policies or use software to automatically extract employee terminal data. Fortunately, there are not many users. Let’s check and register one by one.
1 BAT requirement¶
-
Obtain the manufacturer, version, specifications and other information of the main hardware on the computer;
-
Make it as simple as possible, and the user double-clicks to run it to produce results;
-
The record file is automatically stored in the path where bat is located.
Optimization: In order to facilitate batch downloading of record files without file name conflicts, the user name is required to be entered when running bat on the client, and then the user name is included in the record file name for distinction.
2 BAT code details¶
@echo off & title Get brief configuration information of this machine
::custom username
set /p names=Please enter user name:
::Set information saving path
set Upath=%~dp0
echo detects the current U disk path: %Upath%
set Log="%Upath%" Brief configuration information of this machine (%names%).txt
::Acquisition of main computer hardware information
echo WScript.Echo Wscript.Arguments(0) / (1024 * 1024 * 1024)>Calculation.vbs
echo is getting information...
::Execution results are written to the Log file
(echo login name: %USERNAME%
echo computer name: %COMPUTERNAME%
for /f "tokens=2 delims==" %%a in ('wmic csproduct get Name /value ^| findstr /i "Name"') do echo Computer model: %%~a
for /f "tokens=2 delims==" %%a in ('wmic csproduct get Vendor /value ^| findstr /i "Vendor"') do echo manufacturer: %%~a
for /f "tokens=2 delims==" %%a in ('wmic csproduct get IdentifyingNumber /value ^| findstr /i "IdentifyingNumber"') do echo SN serial number: %%~a
for /f "tokens=2 delims==" %%a in ('wmic cpu get Name /value ^| findstr /i "Name"') do echo processor: %%~a
for /f "tokens=2 delims==" %%a in ('wmic memorychip get Capacity /value ^| findstr /i "Capacity"') do (
for /f "tokens=1 delims=." %%b in ('cscript /nologo Calculation.vbs "%%~a"') do set /a m+=%%~b
)
call echo memory capacity: %%m%% GB
echo.
set /a k=0
for /f "tokens=2 delims==" %%a in ('wmic DiskDrive get Size /value ^| findstr /i "Size"') do (
for /f "tokens=1 delims=." %%b in ('cscript /nologo Calculation.vbs "%%~a"') do set /a d+=%%~b && set /a t=%%~b&&set /a k=k+1
call echo Hard disk %%k%% capacity: %%t%% GB
)
call echo Total hard disk capacity: %%d%% GB
echo.
for /f "tokens=2 delims==" %%a in ('wmic nic where "netconnectionid!=NULL" get macaddress /value ^| findstr /i "MACAddress"') do echo MAC address: %%~a)>"%Log%"
delCalculation.vbs
Echo information is obtained and saved.
pause
3 Execution results¶
Drag the BAT file to any path and double-click to execute it. A computer hardware configuration information record file will be automatically generated in this directory:

This article was moved from WordPress to MkDocs