好的,所以我有以下 Windows 批處理腳本,它可以為所有連接的存儲設備(內部硬盤驅動器/外部 USB 驅動器)提取信息,它工作得很好。但是,我想在它說的後面添加每個檢測到的驅動器的名稱:Volume x:\
像這樣:Volume x:\ NAME OF HDD HERE
。
call :setESC
call :hdd-info
endlocal
echo. Press any key to exit &>nul timeout /t -1 &exit /B
REM - Setup ANSI Escape Character ------------------------------------------------
:setESC
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set ESC=%%b
exit /B 0
)
REM ------------------------------------------------------------------------------
:: - Get Storage / HDD Info ------------------------------------------------------
:hdd-info
:: Enable use of Unicode symbols
chcp 65001 >nul
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('%SystemRoot%\System32\wbem\wmic.exe logicaldisk get deviceid^,freespace^,size^') do (for /f "tokens=1-3" %%j in ("%%i") do call :output %%j %%k %%l)
:: Disable Unicode symbols
chcp 1252 >nul
goto :eof
:output
if "%3"=="" (
:: echo. Volume %optical_drive_letter%\ - %optical_drive_type% ^(%optical_drive_name%^)
goto :eof
)
for /f "tokens=1-4" %%i in (
'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%3/%GB%, 2) & "" "" & FormatNumber((%3-%2)/%GB%, 2) & "" "" & FormatNumber(%2/%GB%, 2) & "" "" & Round((%3-%2)*50/%3)):Close"^)'
) do (
set "size=%%i"
set "used=%%j"
set "free=%%k"
set /a "nUsed=%%l, nFree=50-%%l"
)
echo( Volume %1\
echo( Total Size : %size:~-10%GB
echo( Used Space : %used:~-10%GB
echo( Free Space : %free:~-10%GB
for /l %%i in (1 1 %nUsed%) do <nul set /p "=%ESC%[91m▓%ESC%[30m"
for /l %%i in (1 1 %nFree%) do <nul set /p "=%ESC%[92m▓%ESC%[30m"
echo( &echo(
goto :eof
:: ------------------------------------------------------------------------------
輸出如下:https : //imgshare.io/image/list-hdds.rN55xP
現在,我還有以下內容顯示光驅作為我需要的佈局/信息的示例。IE:在卷標後添加的設備名稱。
請注意此代碼僅作為示例。
:: - Get Optical Drive(s) Information -----------------------------------------------
for /f "skip=2 tokens=2,3 delims=," %%i in (
'%SystemRoot%\System32\wbem\wmic.exe logicaldisk where "drivetype=5" get Caption^ /format:csv'
) Do (
set "optical_drive_letter=%%i"
)
for /f "tokens=2,3 delims=," %%a in (
'%SystemRoot%\System32\wbem\wmic.exe cdrom where "mediatype!=11" get name^,mediatype /format:csv'
) Do (
set "optical_drive_type=%%a"
set "optical_drive_name=%%b"
)
::echo( Volume %optical_drive_letter%\
::echo( %optical_drive_description%/%optical_drive_type% (%optical_drive_name%)
:: ------------------------------------------------------------------------------
echo( Volume %optical_drive_letter%\
echo( %optical_drive_type% (%optical_drive_name%)
echo(
因此,為了澄清上述內容,與初始腳本一樣顯示卷標籤。但是,它也顯示設備名稱。
https://imgshare.io/image/list-optical.rN5bbu
我知道我可以wmic.exe logicaldisk get Caption
在 CMD 中使用它,所以可以在批處理文件中使用這樣的東西:
for /f "delims=^= tokens=2" %%a in ('%SystemRoot%\System32\wbem\wmic.exe PATH Win32_DiskDrive GET Caption /format:list ^| findstr ^=') do set logicaldisk_name=%%a
我的問題是我不知道如何更改原始腳本以獲取並顯示檢測到的每個物理驅動器的每個設備名稱。
任何人都可以幫忙解決這個問題,因為我似乎正在努力使所有連接的驅動器都能正常工作?
完整腳本可以在這裡找到:https : //pastebin.com/q5QS4EmF
非常感謝,
布里
這是完美運行的最新代碼:
setlocal enabledelayedexpansion
for /F "delims=^=,# tokens=3,6" %%A in ('%SystemRoot%\System32\wbem\wmic.exe path Win32_LogicalDiskToPartition get Antecedent^,Dependent ^| find "="') do (
set "disk[%%A]=%%B"
)
set "name=0"
set "GB=1073741824"
for /F "delims=^= tokens=2" %%A in ('%SystemRoot%\System32\wbem\wmic.exe path Win32_DiskDrive get Caption^,Index /value ^| find "="') do (
if !name! EQU 0 (
set hdd_name=%%A
set "name=1"
) else (
set "disk=%%A"
for %%Q in (!disk: ^=!) do (
for /F "skip=1 tokens=1-3 delims= " %%I in ('%SystemRoot%\System32\wbem\wmic.exe LogicalDisk !disk[%%Q]! get DeviceId^,Freespace^,Size') do (
for %%L in (%%I) do (
call :output %%I %%J %%K
)
)
)
SET "name=0"
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句