问题
I want to retrieve serial com port information as device manager shows. For example, "Intel(R) Active Management Technology - SOL (COM3)". I know use command "mode" to retrieve serial port list, but there is no description like "Intel(R) Active Management Technology - SOL". How do I get this information in windows batch file?
回答1:
Updated answer
... was provided by the original asker in the comments below. Apparently Win32_SerialPort doesn't include USB->Serial devices. William's solution to this is to query Win32_PnPEntity instead.
Just so I still feel useful, here's a way to scrape that list and set each line into a variable:
@echo off
setlocal
:: wmic /format:list strips trailing spaces (at least for path win32_pnpentity)
for /f "tokens=1* delims==" %%I in ('wmic path win32_pnpentity get caption /format:list ^| find "COM"') do (
call :setCOM "%%~J"
)
:: display all _COM* variables
set _COM
:: end main batch
goto :EOF
:setCOM <WMIC_output_line>
:: sets _COM#=line
setlocal
set "str=%~1"
set "num=%str:*(COM=%"
set "num=%num:)=%"
set str=%str:(COM=&rem.%
endlocal & set "_COM%num%=%str%"
goto :EOF
Original answer
Use wmic with Win32_SerialPort, something like this:
@echo off
setlocal
for /f "delims=" %%I in ('wmic path Win32_SerialPort get DeviceID^,Caption^,Description^,Name^,ProviderType /format:list ^| find "="') do (
set "%%I"
)
echo %DeviceID%
echo %Caption%
echo %Description%
echo %Name%
echo %ProviderType%
See the documentation for Win32_SerialPort to see what other properties you can query. I'll leave it as an exercise for you to find a way to set the variables uniquely so you aren't overwriting them with iterations over each COM port. Enjoy!
回答2:
Please use mode command to get details of available COM ports..
来源:https://stackoverflow.com/questions/27772861/get-serial-com-port-description-in-windows-batch