- @echo off
- setlocal EnableDelayedExpansion
-
- rem 获取系统版本信息
- for /f "tokens=2 delims=[]" %%i in ('ver') do set "system_version=%%i"
-
- rem 获取CPU信息
- set "cpu_info="
- for /f "tokens=2 delims=[]" %%i in ('wmic cpu get name /value') do set "cpu_info=%%i"
- set "cpu_info=%cpu_info:~1%"
-
- rem 获取内存信息
- set "memory_info="
- for /f "tokens=2 delims=[,]}" %%i in ('wmic memorychip get capacity /value') do set "memory_info=%%i"
- set "memory_info=%memory_info:~0,-1%"
-
- rem 获取主机名
- set "hostname="
- for /f "tokens=2 delims=[,]}" %%i in ('wmic computersystem get name /value') do set "hostname=%%i"
- set "hostname=%hostname:~1%"
-
- rem 获取IP信息
- set "ip_info="
- for /f "tokens=2 delims=[,]}" %%i in ('wmic nicconfig get ipaddress /value') do set "ip_info=%%i"
-
- rem 获取MAC地址信息
- set "mac_info="
- for /f "tokens=2 delims=[,]}" %%i in ('wmic nicconfig get macaddress /value') do set "mac_info=%%i"
-
- rem 获取网关信息
- set "gateway="
- for /f "tokens=2 delims=[,]}" %%i in ('ipconfig ^| findstr /c:"Default"') do set "gateway=%%i"
- set "gateway=%gateway:~1%"
-
- rem 输出结果到文件
- if not exist "%USERPROFILE%\Desktop\systeminfo.txt" (echo System Information > "%USERPROFILE%\Desktop\systeminfo.txt") else (goto :output)
- :output
- echo System Version: %system_version% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo CPU Info: %cpu_info% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo Memory Info: %memory_info% GB >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo Hostname: %hostname% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo IP Info: %ip_info% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo MAC Info: %mac_info% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- echo Gateway: %gateway% >> "%USERPROFILE%\Desktop\systeminfo.txt"
- goto :end
复制代码
|