Skip to content

Instantly share code, notes, and snippets.

@steelywing
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save steelywing/48f965650dc3cf5030a3 to your computer and use it in GitHub Desktop.

Select an option

Save steelywing/48f965650dc3cf5030a3 to your computer and use it in GitHub Desktop.

Revisions

  1. steelywing revised this gist Aug 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion putty-serial.nsi
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ InstallDir "$TEMP"
    RequestExecutionLevel user
    SilentInstall silent

    Section # Create Shortcut
    Section
    SetOutPath $INSTDIR
    File "putty.exe"
    File "putty-serial.vbs"
  2. steelywing revised this gist Aug 22, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions putty-serial.nsi
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # Wrap putty-serial.vbs to exe
    Name "PuTTY Serial"
    Icon "putty.ico"

  3. steelywing revised this gist Aug 22, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions putty-serial.nsi
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    Name "PuTTY Serial"
    Icon "putty.ico"

    OutFile "putty-serial.exe"
    InstallDir "$TEMP"
    RequestExecutionLevel user
    SilentInstall silent

    Section # Create Shortcut
    SetOutPath $INSTDIR
    File "putty.exe"
    File "putty-serial.vbs"
    ExecShell "" '"$TEMP\putty-serial.vbs"'
    SectionEnd
  4. steelywing revised this gist Aug 22, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions putty-serial.vbs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    Const PUTTY_PATH = "putty"

    ' Return array of serial port number
    Function getCOM()
    Dim fso, com()
    ReDim com(-1)
    @@ -30,7 +33,7 @@ If UBound(com) = -1 Then
    End If

    If UBound(com) = 0 Then
    CreateObject("WScript.Shell").Exec("putty -serial COM" & com(0))
    CreateObject("WScript.Shell").Exec(PUTTY_PATH & " -serial COM" & com(0))
    WScript.Quit
    End If

    @@ -39,7 +42,7 @@ 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 -serial COM" & com(i))
    CreateObject("WScript.Shell").Exec(PUTTY_PATH & " -serial COM" & com(i))
    WScript.Quit
    End If
    Next
  5. steelywing revised this gist Aug 22, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions putty-serial.vbs
    Original file line number Diff line number Diff line change
    @@ -31,6 +31,7 @@ End If

    If UBound(com) = 0 Then
    CreateObject("WScript.Shell").Exec("putty -serial COM" & com(0))
    WScript.Quit
    End If

    ' COM more than 1
  6. steelywing created this gist Aug 22, 2015.
    44 changes: 44 additions & 0 deletions putty-serial.vbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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 -serial COM" & com(0))
    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 -serial COM" & com(i))
    WScript.Quit
    End If
    Next