Change Device Serial Port Number using AHK â
Prerequisite â
Device Console executable devcon.exe
is required, and is only available to download from Windows WDK (Windows Driver Kit).
Download it from https://learn.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
In the installation wizard, ignore and proceed when it prompted that it couldn't find any Visual Studio development kit and if you still wish to continue.
Finding Device ID â
You need to find the serial port Device ID as registered in Windows, this argument will later be passed over to devcon.exe
to change its com port.
AHK Script â
ahk
; Define paths to DevCon executable and device ID
devconPath := "C:\Path\To\DevCon\devcon.exe"
deviceId := "USB\VID_XXXX&PID_XXXX\XXXXXXXXXXXXXXXX" ; Replace with your device ID
; Function to change the COM port using DevCon
ChangeCOMPort(oldCOM, newCOM) {
global devconPath, deviceId
RunWait, % devconPath " disable " deviceId,, Hide
RunWait, % devconPath " set " deviceId " portname=" newCOM,, Hide
RunWait, % devconPath " enable " deviceId,, Hide
}
; Change COM port from COM99 to COM1 before running start.bat
ChangeCOMPort("COM99", "COM1")
; Run start.bat
Run('start.bat')
Esc:: {
If (A_PriorHotkey = "Esc" && A_TimeSincePriorHotkey < 500) {
ProcessClose("mu3.exe")
Run("taskkill /im mu3.exe /F",, "Hide")
; Change COM port from COM1 back to COM99 before exiting
ChangeCOMPort("COM1", "COM99")
ExitApp
}
}