在Windows批处理中获取串行com端口描述 [英] get serial com port description in windows batch

查看:260
本文介绍了在Windows批处理中获取串行com端口描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检索串行com端口信息,如设备管理器所示.例如,英特尔®主动管理技术-SOL(COM3)". 我知道使用命令模式"来检索串行端口列表,但是没有像英特尔(R)主动管理技术-SOL"这样的描述.如何在Windows批处理文件中获取此信息?

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?

推荐答案

更新的答案

...由原始提问者在以下评论中提供.显然Win32_SerialPort不包括USB->串行设备.威廉姆(William)的解决方案是查询 Win32_PnPEntity .

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


原始答案

wmicWin32_SerialPort一起使用,如下所示:


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%

请参阅Win32_SerialPort 查看您还可以查询哪些其他属性.我将把它作为练习,让您找到一种唯一设置变量的方法,这样您就不会在每个COM端口上通过迭代覆盖它们.享受吧!

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!

这篇关于在Windows批处理中获取串行com端口描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆