找回密码
 加入
搜索
查看: 229|回复: 5

有没有办法检查是否存在某个com口

[复制链接]
发表于 2024-8-15 17:26:28 | 显示全部楼层 |阅读模式
比如想知道本机有没有com2口,如何实现?

另外有没有办法删除现有的com口,然后刷新硬件列表?
谢谢各位老师!
发表于 2024-8-17 10:23:20 | 显示全部楼层
本帖最后由 msold5 于 2024-8-17 10:25 编辑

既然COM口也是文件,那么应该可以用文件方法来判断,类似于批处理中的if exist  com1  echo ok
删除好像要用到系统里自带的dism或者另一个啥程序,你自己再查查呢
发表于 2024-8-17 10:32:40 | 显示全部楼层
论坛搜索一下com,应该会有结果,com就当文件来处理。
发表于 2024-8-19 01:16:16 | 显示全部楼层
#include <Array.au3>
#include <CommMG.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Opt("GUICloseOnESC", 0) ;1 = 點擊 Esc 鍵關閉, 0 = 點擊 Esc 鍵不關閉
Opt("TrayIconHide", 0) ;0 = 顯示托盤圖標, 1 = 隱藏托盤圖標
Opt('MustDeclareVars', 1);1 = 變量不需預先聲明, 1 = 變量必需預先聲明

Local $hGUI = GUICreate("com_port-check", 200, 200)

GUISetState(@SW_SHOW)
CommLoad()

While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE ;離開
                        _CommCloseport()
                        EXIT
        EndSwitch
WEnd


Func CommLoad() ;commPort_Load
    Local $portnum = "" , $portnum_temp = "" , $portlist1 = "", $ComPort_Total
    Local $portlist = _CommListPorts(0)
        _ArrayDisplay($portlist)
    If $portlist[0] >= 1 Then
                For $pl = 1 To $portlist[0]
                        $portlist1 = _ComGetPortNames($portlist[$pl])
                        $portnum_temp = StringReplace($portlist[$pl], "COM", '')
                        $ComPort_Total &= $portnum_temp & "|"
                Next
                _CommSetTimeouts(5,5,5,5,5)
                Local $sz2 = StringSplit($ComPort_Total,'|',3)
                _ArraySort($sz2 ) ;埠位排序
                $ComPort_Total = ""
                For $pl = 1 To (UBound($sz2,1)- 1)
                        $ComPort_Total &=  $sz2[$pl]& "|"
                Next
                MsgBox(0,"",$ComPort_Total)
        Else
                MsgBox(0,"串列Port錯誤","無串列Port,程式關閉。")
                Exit
    EndIf
EndFunc

:---- 給你參考看看
 楼主| 发表于 2024-8-20 08:32:37 | 显示全部楼层
yohoboy 发表于 2024-8-19 01:16
#include
#include
#include

谢谢老师,这个用到CommMG.au3,编译成执行文件之后,是不是也还需要那个dll文件才能正常运行?
发表于 2024-8-21 01:02:31 | 显示全部楼层
bluecap 发表于 2024-8-20 08:32
谢谢老师,这个用到CommMG.au3,编译成执行文件之后,是不是也还需要那个dll文件才能正常运行? ...

正確,那個是for 32位元的dll檔,但在64位元的系統還是可以運作。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-27 11:28 , Processed in 0.071416 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表