看板 Visual_Basic 關於我們 聯絡資訊
我是用你第二個方法~ Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_PnPEntity where Name like '%(com%)%'") For Each objItem In colItems strportnum = Replace(Mid(objItem.Name, InStr(objItem.Name, "COM") + 3, 4), ")", "") On Error Resume Next If Err.Number <> 0 Then isopen = True: Resume rrr Else isopen = False rrr: Combo3.AddItem ("COM" & CStr(strportnum)) vbTab & isopen & vbNewLine Next ※ 引述《hirabbitt (兔子)》之銘言: : 從網路上找到的方法1 : Set obj = : GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") : Set items = obj.ExecQuery("Select * from Win32_SerialPort") : For Each item In items : //item.DeviceID 就是要找的port : Next : 但是我以這種方式去做 : 好像只能找到com1和com2 : 另外接上去的com6並沒有出現 : 而且 : 我看不懂obj和items那邊在做什麼QQ : ======================================== : 又找了方法2 : 只是把items的語法換掉而已 : 變成 : Set items = : obj.ExecQuery("Select * from Win32_PnPEntity where Name like %(com%)%") : 結果跑出Automation Error : 我把where後面的語句刪掉後 : Set items = obj.ExecQuery("Select * from Win32_PnPEntity") : 雖然沒有出錯 : 但是跑出一堆看不懂的port : 像是ROOT\ACPI_HAL\0000等等 : 而且也沒有我要的com6 : ========================================== : 然後找了方法3 : 是生一個MSComm物件 : 然後用for一個一個port去試能不能開啟 : 這方法終於成功的找到我的com6 : 可是感覺有點笨? : =========================================== : 想請問 : 是不是沒有其他方式了? : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.87.152.131 ※ 編輯: timohu 來自: 219.87.152.131 (05/11 16:58) ※ 編輯: timohu 來自: 219.87.152.131 (05/11 16:59)
TroyLee:HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM ? 05/16 01:34