2014-09-23 75 views
0

我有這個簡單的腳本,幫助我的一些用戶將SSH通過VNC轉換爲服務器上的非專用帳戶。我正在使用Putty和TightVNC,它們與腳本位於同一目錄中。它是這樣的:VBScript - 創建並在一個隱藏的窗口中殺死一個進程?

Dim sshtunnel 
Dim desktop 

Set tunnel = WScript.CreateObject("WScript.Shell") 
Return = tunnel.run("putty -ssh [email protected]#.#.#.# -L 9000:localhost:5901 -pw password",0,false) 
Set desktop = WScript.CreateObject("WScript.Shell") 
Return = desktop.run("tvnviewer -host=localhost -port=9000",0,true) 
'Somehow, end the process created by tunnel.run 

步驟:
1)開始膩子用適當的端口轉發無形(工作
2)啓動遠程桌面(工作
3)等待遠程桌面會話被關閉(作品
4)關閉SSH隧道(殺膩子)(需要幫助

很顯然,我需要它來殺死膩子 - 但我找不到任何方式與以tunnel.run方法開始的進程進行通信。我無法找到一種方法來使用exec隱形進行創建。我應該如何處理這個問題?

謝謝!
PS:我知道有一個硬編碼的密碼。在這種情況下,在部署時進行補救更爲合適。

回答

1

很多方法。適合你正在做的是運行taskkill。

Return = tunnel.run("taskkill /im PuTTY.exe /f",0,false) 

Return = tunnel.run("wmic process where (Name=""PuTTY.exe"") call terminate",0,false)