2012-09-22 35 views
3

我是VB腳本新手。其實我想運行一些應用服務器的telnet命令。如何使用VB腳本以靜默模式運行telnet?

我在客戶端PC上運行該VB腳本(操作系統:Windows server 2003)。該腳本運行良好。

現在的問題是,雖然Telnet是通過VB腳本運行,我不能做任何事情,

PC上的其他人。我希望該腳本在後端運行。即處於靜音模式。

以下是我正在使用的VB代碼。

set oShell = CreateObject("WScript.Shell") 
oShell.run"cmd.exe" 
WScript.Sleep 500 
oShell.SendKeys"telnet x.x.x.x -f roamingsubscriber.txt" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1500 
oShell.SendKeys"username" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 500 
oShell.SendKeys"password" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 500 
oShell.SendKeys"command" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1000 
oShell.SendKeys"command" 
oShell.SendKeys("{Enter}") 
WScript.Sleep 1000 
... 

回答

0

沒有辦法,直到你找到你完成任務或開發一個ActiveX組件將啓動telnet過程,而不需要通過管道創建一個控制檯窗口和管道的輸入和輸出。至少WScript.Shell不提供此類功能。

1

看到這個網站http://www.dimac.net/default3.asp?M=FreeDownloads/Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp免費的ActiveX compont做這種事情。 這裏是API

http://www.dimac.net/products/freeproducts/w3sockets/reference/refstart.htm 

這裏一些示例代碼

Set oSocket = WScript.CreateObject("Socket.TCP") 
oSocket.DoTelnetemulation = True 
osocket.Timeout = 1000 
oSocket.Host = "host.somewhere.com" & ":" & 80 
oSocket.Open 
oSocket.SendLine("GET /" & vbCrLf) 
data = oSocket.GetLine 
If (Instr(data, "yourtest")) then 
    ' doSomething 
End if 
oSocket.Close