找回密码
 加入
搜索
查看: 2975|回复: 3

[AU3基础] 求助!使用Run运行teraterm建立ssh连接时,返回pid对应多个窗口[已解决]

[复制链接]
发表于 2011-8-26 23:19:11 | 显示全部楼层 |阅读模式
本帖最后由 runtium 于 2011-9-4 20:58 编辑

在利用Run来建立teraterm的ssh连接时, 返回的pid并不是最后连接完成窗口(ssh)的进程id,而是一个叫TTSSH的进程id.
==================================================
-->Line(0013):        pid1=3012,hwnd1=0x000A089A
+======================================================
-->Line(0014):        title1=TTSSH: SCP sending file
+======================================================
-->Line(0017):        ====what i want====
+======================================================
-->Line(0018):        pid2=3856,hwnd=0x001906DE
+======================================================
-->Line(0019):        title2=192.168.0.3:22 - ~ VT
+======================================================

我最终想要的是ssh连接窗口的handle, 因为可能同时存在多个这样的ssh连接, teraterm窗口的title是一样的, 所以不能使用title来获得handle
求各位大侠帮忙!有不对的地方,请指教!
#include <Array.au3>
Opt("WinTitleMatchMode", 2)     ;1=start, 2=subStr

$ssh = "C:\Program Files\teraterm\ttermpro.exe 192.168.0.3:22 /ssh2 /auth=password /user=Admin /passwd=admin"

$pid = Run($ssh,"",@SW_MINIMIZE)

Sleep(5000)
$hwnd = _PID2HWND($pid)

_DebugPrint("pid1="&$pid&",hwnd1="&$hwnd)
_DebugPrint("title1="&WinGetTitle($hwnd))
_DebugPrint("====what i want====")
_DebugPrint("pid2="&WinGetProcess("192.168.0.3")&",hwnd="&WinGetHandle("192.168.0.3"))
_DebugPrint("title2="&WinGetTitle("192.168.0.3"))

Func _PID2HWND($pid)
        $list = WinList()
        For $i = 1 To $list[0][0]
                If WinGetProcess($list[$i][1]) = $pid Then
                        Return $list[$i][1]
                EndIf
        Next
        Return 0
EndFunc

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
 楼主| 发表于 2011-8-27 11:14:30 | 显示全部楼层
强人们过来看看啊!!
 楼主| 发表于 2011-8-27 11:14:38 | 显示全部楼层
强人们过来看看啊!!
 楼主| 发表于 2011-9-4 20:57:18 | 显示全部楼层
没人回答...

之前问题提的也有点问题, 经过多次尝试, 那个pid对应有多个窗口, 也包括最后那个teraterm的窗口
这样的话, 可以在_PID2HANDLE中加一个窗口title的匹配,得到最后所要的handle
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 23:30 , Processed in 0.077141 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表