2017-04-08 88 views
0

我想知道如何在初始登錄成功後在putty中自動輸入用戶名和密碼。使用批次在putty中輸入第二個用戶名和密碼

我有一個bat文件connect.bat

@echo off 

putty [user]@[host] -pw [password] 

我運行此之後,它會打開一個新的窗口,膩子和驗證的登錄。

成功時,我不會重定向到shell,而是重定向到另一個登錄屏幕。下面的示例。

enter image description here

然後我需要通過鍵入以下手動輸入不同的用戶名和密碼。

[username] 
[ENTER KEY] 
[password] 
[ENTER KEY] 

最終被重定向到主菜單。

我試過如下:

echo [username] & [password] | putty [user]@[host] -pw [password] 

putty [user]@[host] -pw [password] < user_pass.txt 
putty [user]@[host] -pw [password] -m user_pass.txt 

但失敗了,是否有通過批處理/ PowerShell腳本來執行此,或者我應該包括其他應用程序的方法嗎?

+0

所以它的一些X Server應用程序,對不對?那不能是PuTTY屏幕。 –

回答

1

您可以嘗試Sendkeys method

@if (@CodeSection == @Batch) @then 


@echo off 

rem Use %SendKeys% to send keys to the keyboard buffer 
set SendKeys=CScript //nologo //E:JScript "%~F0" 

rem Start the other program in the same Window 
start "" /B putty [user]@[host] -pw [password] 

rem Send the additional keys 
%SendKeys% "[username]{ENTER}" 
ping -n 2 localhost > NUL 
%SendKeys% "[password]{ENTER}" 

goto :EOF 


@end 


// JScript section 

var WshShell = WScript.CreateObject("WScript.Shell"); 
WshShell.SendKeys(WScript.Arguments(0)); 
+0

我試過了,但是我有一個錯誤。我應該安裝還是激活一些應用程序? C:\文件> connect.bat C:\文件>如果(@CodeSection == @Batch) C:\文件\ connect.bat(1,17)微軟的JScript編譯錯誤:條件COM pilation是關閉 C:\文件\ connect.bat(1,17)Microsoft JScript中的編譯錯誤:有條件的COM pilation關閉 C:\文件> – Treize

+0

行動!我有一個錯字!第一個IF必須在@if(@CodeSection == @Batch)@ then'之前有一個at-sign ...我已經在代碼中修復了它 – Aacini

+0

很酷我測試了它,它工作正常,非常感謝! – Treize

相關問題