首页 > 解决方案 > 在 VBA 宏中使用 SSH 传递命令但无法在 excel 上获得响应

问题描述

使用 Windows 的 Excel VBA 中的 SSH 输出出现问题。

我曾尝试使用 SSH 运行相同的东西,它工作正常,但是当我尝试使用 VBA 时,它显示它正在工作,但没有显示任何内容。

Sub CreateSSHTunnelUsingPutty()
    Dim strFilename As String, strCommandLine As String
    Dim strCurrPath As String
    Dim lngWindowHandle As Long
    Dim strServerPOrt As Long
    Dim strServerUser As String
    Dim strServerPassword As String
    Dim IPAdd As String
    Dim rng As Range, cell As Range

    strServerPOrt = 22                           'Sample POrt
    strServerUser = "username"                   'Sample User Name
    strServerPassword = "password"               'Sample Password
    'Set rng = Range("B2:B75")

    For Each cell In ActiveSheet.Range("B2:B2")
        IPAdd = cell.Value
        strFilename = "Plink.exe"
        strCommandLine = IPAdd & " -P " & strServerPOrt & " -l " & strServerUser & " -pw " & strServerPassword

        'Launch tunnel
        Call lbf_ShellExecute(0, "open", strFilename, strCommandLine, "", 1)
        'Change the last parameter from a one to a zero and the connection window will be hidden.

        Sleep (3000)


'Here i want to give my commands so that output will be displayed on Sheet 1 Starting Row 3

End Sub

可以说,如果我放版本,那么它应该显示版本或 top 命令将导致所有内存详细信息。

标签: excelvbawindowsssh

解决方案


推荐阅读