larksp Posted February 15, 2017 Share Posted February 15, 2017 sometimes after i reinstall a w7 Acer . it shows 2 com ports Most of the time it sets the right 1 to com1. there is only 1 serial port on the back of the computer . A DP1 & dp2 also a dvi-d (plus normal ones) I know how to use Wmi to show there are 2 com ports on the pc "SELECT * FROM MSSerial_PortName" OR SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)' I see there are few udfs to do alot more than i would want and not sure if they can do this just a simple check com ports and switch them rather than going device manager checking to see if there are more than 1 port then changing it (Port in use so have to change "1 TO 3" "2 TO 1" "3 TO 2 ) If this is harder than it seems just say and i wont bother Link to comment Share on other sites More sharing options...
Subz Posted February 15, 2017 Share Posted February 15, 2017 Have you tried the following UDF, _CommListPorts, _CommSetPort functions in particular. Link to comment Share on other sites More sharing options...
larksp Posted February 16, 2017 Author Share Posted February 16, 2017 i will have a look now hopefully but am getting bit sleepy Link to comment Share on other sites More sharing options...
larksp Posted February 16, 2017 Author Share Posted February 16, 2017 i will have a play with the code either Tuesday or try find a pc lying around that actually has a com port as my main computers at home dont Link to comment Share on other sites More sharing options...
jguinch Posted February 16, 2017 Share Posted February 16, 2017 I'm not sure to understand what you want to do. You want to change the COM port assignment ? Set the COM1 to use the COM3 name ? Maybe this article could help you : Re-Assigning COM Port Numbers Using the Windows Registry Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
larksp Posted February 16, 2017 Author Share Posted February 16, 2017 (edited) yes on some of the acer computers under com ports(Device manager) has 2 Ports "com1 and com2..." but only 1 port to plug the cable in. some times after a reinstall of windows the real serial port (where the cable plugs in) instead is now com2. so i just want to change it back to com1 doing this the manually way i have to set com1 to com3 so that i can set com2 to com1.. you cant just set com2 to com1 as there is already com1 assigned (Motherboard assigned ports) Edited February 16, 2017 by larksp ref to what ports Link to comment Share on other sites More sharing options...
jguinch Posted February 16, 2017 Share Posted February 16, 2017 With the Win32_SerialPort WMI class, you can check if the property PNPDeviceID is different between the 2 ports (with a Acer computer having two COM ports). You maybe you will be able to determine in which case you have to re-assign the COM port. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
larksp Posted February 16, 2017 Author Share Posted February 16, 2017 _PnPEntity() Func _PnPEntity() Local $Array[0][3] Local $WMI = ObjGet("winmgmts:\\localhost\root\CIMV2") Local $Port = $WMI.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'", "WQL", 48) If IsObj($Port) Then For $col In $Port ReDim $Array[UBound($Array) + 1][3] $Array[$I][0] = $I + 1 $Array[$I][1] = $col.Name $Array[$I][2] = $col.PNPDeviceID $I += 1 Next EndIf untested as this pc has no comport i think Win32_PnPEntity from https://msdn.microsoft.com/en-us/library/aa394353(v=vs.85).aspx has PNPDeviceID would ov need to add array display to see it Link to comment Share on other sites More sharing options...
larksp Posted February 16, 2017 Author Share Posted February 16, 2017 still dont know how to do the re-assign part tho the doc you posted is in hex and it does say the first 2 hex numbers is com 1 and com 2 i think but i dont understand hex lol Link to comment Share on other sites More sharing options...
jguinch Posted February 16, 2017 Share Posted February 16, 2017 I made some tests on my computer to re-assign com1 to com2. I managed to do it though the registry. I understand how it works now, here is my explanation (I hope it will be clear enough). First, you have to get sufficient rigths in some registry keys (like HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter because you don't have enough rights to write in the key, even if you use an administrator account). In the above registry key, the value ComDB contains the list of the COM ports used by the system. On my computer its value is 0x0500000000000000000000000000000000000000000000000000000000000000 The binary value is made like this : - the first byte represents the state of use for COM1 To COM8 : on my computer, the value is 05 (or 0x05). In real binary it's equal to 00000101 (COM3 and COM1 used) - the next byte represents COM9 to COM16 and so on... So the first thing to do is to check if the desired port is used or not using this value : Local $ComDB = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter", "ComDB") Local $iLen = BinaryLen($ComDB) Local $iByte, $iPortNum, $iDec For $i = 1 To $iLen $iByte = BinaryMid($ComDB, $i, 1) For $j = 1 To 8 $iPortNum = ($i - 1) * 8 + $j $iDec = 1 * 2 ^ ($j - 1) If BitAND($iByte, $iDec) Then ConsoleWrite("Port " & $iPortNum & " used " & @CRLF) Next Next Next you will have to calculate the new ComDB value : set the old port number as not used and the new port number as used. For example, if you want to set COM2 and COM3 as used and COM1 as not used, the value in real binary will be 00000110 = 0x06. So the new ComDB value to write will be 0x0600000000000000000000000000000000000000000000000000000000000000 After that, you have to remove the registry value corresponding to the old port and add the new one in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports - add the COM2 value and set its value to the same than COM1 - remove the COM1 value if not used Next you will have to apply changes in - HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM\ : \Device\Serial0 - \Device\Serial0 - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI\PNP0501\1 : FriendlyName (it's the PNDDeviceID found with the WMI query) - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\ACPI\PNP0501\1\Device Parameters : PortName This is not trivial... larksp 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
larksp Posted February 17, 2017 Author Share Posted February 17, 2017 thanks for the reply.... I understand witch is good as means I have learnt more and more as i use autoit lol... next time im on acer pc ill check the reg for it.. and maybe also open one that set ok and one that is not to see if there different as well Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now