Last active
August 29, 2015 14:27
-
-
Save steelywing/48f965650dc3cf5030a3 to your computer and use it in GitHub Desktop.
Auto detect serial port to execute putty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Wrap putty-serial.vbs to exe | |
Name "PuTTY Serial" | |
Icon "putty.ico" | |
OutFile "putty-serial.exe" | |
InstallDir "$TEMP" | |
RequestExecutionLevel user | |
SilentInstall silent | |
Section | |
SetOutPath $INSTDIR | |
File "putty.exe" | |
File "putty-serial.vbs" | |
ExecShell "" '"$TEMP\putty-serial.vbs"' | |
SectionEnd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Const PUTTY_PATH = "putty" | |
' Return array of serial port number | |
Function getCOM() | |
Dim fso, com() | |
ReDim com(-1) | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
For i = 1 To 20 | |
Dim f, found | |
On Error Resume Next | |
Set f = fso.OpenTextFile("COM" & i & ":", 2) | |
' Err.Clear | |
found = (Err.Number = 0) | |
f.Close | |
On Error Goto 0 | |
If found Then | |
ReDim Preserve com(UBound(com) + 1) | |
com(UBound(com)) = i | |
End If | |
Next | |
getCOM = com | |
End Function | |
Dim WshShell, com | |
Set WshShell = WScript.CreateObject("WScript.Shell") | |
com = getCOM() | |
If UBound(com) = -1 Then | |
WScript.Echo "No COM found" | |
WScript.Quit | |
End If | |
If UBound(com) = 0 Then | |
CreateObject("WScript.Shell").Exec(PUTTY_PATH & " -serial COM" & com(0)) | |
WScript.Quit | |
End If | |
' COM more than 1 | |
For i = 0 to UBound(com) | |
Dim answer | |
answer = WshShell.Popup("Use COM" & com(i) & " ?", , "COM port", 4 + 32) | |
If answer = 6 Then | |
CreateObject("WScript.Shell").Exec(PUTTY_PATH & " -serial COM" & com(i)) | |
WScript.Quit | |
End If | |
Next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment