2013-08-20 44 views
-4
private void RDP(string pass) 
{ 
    try 
    { 
     rdp.Server = TBIP.Text; 
     rdp.UserName = TBUserName.Text; 
     IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx(); 
     secured.ClearTextPassword = pass; 
     rdp.Connect(); 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine(ex); 
    } 
} 

本标准的要求是工作完美:RDP客户端环

RDP("123"); 

如何我可以做一个循环。这例如不起作用:

foreach (var p in pwd) 
{ 
    RDP(p); 
    Thread.Sleep(30 * 1000); 
    rdp.Disconnect(); 
    rdp.AllowDrop = true; 
} 

它会在'59'行抛出一个错误。

rdp.Server = TBIP.Text; 

“异常输出”

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in AxInterop.MSTSCLib.dll 
System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component. 
    at MSTSCLib.IMsRdpClient8.set_Server(String pServer) 
    at AxMSTSCLib.AxMsRdpClient8.set_Server(String value) 
    at RDP.Form1.RDP() in c:\Users\x\Documents\Visual Studio 2012\Projects\RDP\RDP\Form1.cs:line 59 
+1

什么是错误? – CristisS

+2

小心分享错误讯息还是猜猜游戏? “不起作用”意味着你得到一个错误,*正确*? **什么错误**? – Arran

回答

0

我可以重复你的错误,但我不能与RDP进行广泛的测试,但也许this post可以帮助你。