How to call and execute a shell script using PuTTY from VBA macro

非 Y 不嫁゛ 提交于 2019-12-07 07:15:26
  • You have to quote the path to PuTTY, as it contains spaces.

  • Also you execute putty.exe twice. Instead you have to pass all those parameters to a single instance of putty.exe

pc1 = """C:\Program Files (x86)\PuTTY\putty.exe"" " & _
    "-ssh " & UserName & "@ip address -pw " & Passwrd & " -m ""C:\Temp\emu.sh"""
TaskID = Shell(pc1, 1)

And you should consider using plink.exe instead of putty.exe, what is a PuTTY tool intended to automation. PuTTY is GUI application intended for an interactive use.

File paths with spaces need to be quoted:

Sub open_putty()
    Dim UserName 'assign user name
    Dim Passwrd 'assign password
    Dim TaskID As Long
    UserName = "user name"
    Passwrd = "password"
    pc1 = """C:\Program Files (x86)\PuTTY\putty.exe"" -ssh " & _
           UserName & "@ip address -pw " & Passwrd
    pc2 = "putty.exe -m ""C:\Temp\emu.sh"""
    TaskID = Shell(pc1, 1)
    TaskID = Shell(pc2, 1)

End Sub
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!