rem 采集cpu信息,若多核,則顯示多條結果
for /f "skip=1" %%i in ('wmic CPU GET LoadPercentage') do (
if %%i geq 0 set cpuStr=%%i%%
)
echo CPU使用率:%cpuStr%
采集內存信息
rem 采集內存總容量
for /f "skip=1" %%i in ('wmic os get TotalVisibleMemorySize') do (
if %%i geq 0 set totalMem=%%i
)
set /a tmp=%totalMem%/1024
set totalMem=%tmp:~0,-3%.%tmp:~-3%Gecho 總內存容量:%totalMem%
echo -----------------------------------------
rem 設置2秒的延遲
ping 127.0.0.1 -n 2 > nullrem 采集可用內存容量
for /f "skip=1" %%i in ('wmic os get FreePhysicalMemory') do (
if %%i geq 0 set freeMem=%%i
)
set /a tmp=%freeMem%/1024
set freeMem=%tmp:~0,-3%.%tmp:~-3%Gecho 空閑內存容量:%freeMem%
采集磁盤信息
rem 采集磁盤信息
echo 磁盤信息(可用/總量)
wmic LOGICALDISK get DeviceID,FreeSpace,Size > tmp.txt
for /f "skip=1 tokens=1,2,3*" %%i in ('type tmp.txt') do (
set totalDisk=%%k
set freeDisk=%%j
set /a tmp1=!freeDisk:~0,-5!/1074
set /a tmp2=!totalDisk:~0,-5!/1074
set diskStr=%%i!tmp1:~0,-1!.!tmp1:~-1!G/!tmp2:~0,-1!.!tmp2:~-1!G
echo !diskStr!
)
del tmp.txt
采集TCP端口信息
echo TCP port:
FOR /F "tokens=3,5* delims=: " %%i IN ('netstat -anp tcp') do (
if %%k == LISTENING set tcpStr=!tcpStr!%%i
)
echo %tcpStr%
采集UDP端口信息
echo UDP port:
FOR /F "tokens=1,2,3* delims=: " %%i IN ('netstat -anp udp') do (
if %%i == UDP set udpStr=!udpStr!%%k
)
echo %udpStr%
顯示自啟程序的執行路徑
echo 自啟程序路徑:
rem for /f "skip=1" %%i in ('wmic STARTUP GET Command') do (
rem echo %%i
rem )
wmic STARTUP GET Command