Consulting

Results 1 to 2 of 2

Thread: How to run Putty session with Plink from VBA macro

  1. #1
    VBAX Newbie
    Joined
    Sep 2020
    Posts
    1
    Location

    How to run Putty session with Plink from VBA macro

    I am trying to automate an ssh session by starting a putty session using plink.exe from a VBA macro. Part of the automation is sending some commands to a linux server. After I run the macro; plink opens in a blank command prompt window but closes a few seconds later . This is the line that attempts to run plink.exe
    Set oExec = WshShell.exec("plink.exe -load aaTest")
    . I suspected originally that it might be improper string formatting. However, when I try to run the putty gui from the same macro by replacing the above line with
    Set oExec = WshShell.exec("putty.exe -load aaTest")
    , the putty gui opens and I can login. The StdIn.Write code doesn't work and that is because putty doesn't use StdIn. But I don't get why plink isn't working. What am I doing wrong here?

    Here is the complete macro:

    Sub AutoMop()
    '
    ' AutoMop Macro
    '
    '
    Set WshShell = VBA.CreateObject("WScript.Shell")
    WshShell.CurrentDirectory = ("C:\Users\lxp\Core\91CS\PuTTY")
    Set oExec = WshShell.exec("plink.exe -load aaTest")
    
    
    ' Write to the input stream
    oExec.StdIn.Write "service ssh status" & vbCrLf
    'Application.Wait (Now + TimeValue("0:00:00:05"))
    oExec.StdIn.Write "sudo service ssh restart" & vbCrLf
    
    End Sub


  2. #2
    VBAX Newbie
    Joined
    Oct 2020
    Location
    Berlin, Germany. Often vivst Ukraine for business
    Posts
    2
    Location
    Have you already found a solution?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •