2016-06-07 93 views
6

我正在使用'Microsoft终端服务控件类型库'建立与远程桌面服务器的连接。我正在寻找一种方法来防止或禁止在连接到使用网络级身份验证(NLA)的远程桌面服务器时提供正确的用户名/密码组合时显示的“Windows安全性”提示。该窗口看起来是这样的:使用网络级别身份验证失败向远程桌面服务器提供适当的凭据后,防止登录尝试失败窗口

enter image description here

我看了一下,在这个时候尝试网上的设置每一个组合,我可以找到和他们都没有成功。这里有几个我发现stackoverlow是谈论这个确切的问题,也应该把它解决了,但答案不是为我工作的问题:

AxMsRdpClient9 Dismiss login dialog

AxMsRdpClient6NotSafeForScripting AllowPromptingForCredentials

这可能听起来很可笑,但我的最终目标是尝试连接到rdp服务器并故意输入无效的用户名/密码,然后在失败时断开连接。我不关心实际连接或显示任何东西。如果它很重要,我这样做是为了试图在远程服务器上的事件日志中触发失败的登录尝试,而其他应用稍后将使用该日志。

下面的代码已经在事件日志中触发了失败的登录尝试,但我无法找到一种方法来阻止在客户端计算机上弹出失败的登录框,我宁可不诉诸黑客试图关闭窗口打开后。当远程桌面服务器配置为允许运行任何版本的远程桌面的计算机连接时(安全性较低的选项),我不会遇到同样的问题,因为弹出式提示显然是NLA提供的额外安全性的一部分。

我已经尝试过这么多不同的设置组合,这是我头部旋转的控制。这里是上面的计算器等问题之一仿照一个例子:

Public Class Form1 
    Dim WithEvents oRemote As AxMSTSCLib.AxMsRdpClient6NotSafeForScripting 

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     oRemote = New AxMSTSCLib.AxMsRdpClient6NotSafeForScripting 
     CType(oRemote, System.ComponentModel.ISupportInitialize).BeginInit() 
     oRemote.Dock = System.Windows.Forms.DockStyle.Fill 
     oRemote.Enabled = True 
     oRemote.Name = "OfficeWin7" 
     Me.Controls.Add(oRemote) 
     CType(oRemote, System.ComponentModel.ISupportInitialize).EndInit() 
     oRemote.CreateControl() 
     oRemote.Size = New System.Drawing.Size(800, 600) 

     oRemote.Server = "IPADDRESS" 
     oRemote.UserName = "TestAccount" 
     oRemote.AdvancedSettings7.ClearTextPassword = "WrongPassword" 

     Dim ocx As MSTSCLib.IMsRdpClientNonScriptable4 = oRemote.GetOcx() 

     ocx.EnableCredSspSupport = True 
     ocx.AllowCredentialSaving = False 
     ocx.PromptForCredentials = False 
     ocx.PromptForCredsOnClient = False 

     oRemote.Connect() 
    End Sub 

    Private Sub oRemote_OnAuthenticationWarningDismissed(sender As Object, e As EventArgs) Handles oRemote.OnAuthenticationWarningDismissed 
     MessageBox.Show("The credentials popup is now closing") 
    End Sub 

    Private Sub oRemote_OnAuthenticationWarningDisplayed(sender As Object, e As EventArgs) Handles oRemote.OnAuthenticationWarningDisplayed 
     MessageBox.Show("The credentials popup is about to be shown") 
    End Sub 
End Class 

据说它是ocx.PromptForCredentials = False行应防止这个弹出,但似乎不有所作为如果该值设置为TrueFalse。我几乎可以假设房产名称ocx.PromptForCredsOnClient实际上可能会工作,但同样,我设定这个价值并没有什么不同。我总是得到相同的弹出窗口。

在这一点上我不知道我做错了,但我的直觉告诉我,得到这个工作,我需要实例化基地AxMsRdpClient6NotSafeForScripting对象为别的像AxMsRdpClient9NotSafeForScripting甚至AxMsTscAxNotSafeForScripting这是默认的输入控制用途当我把它放到表单上。我已经尝试了一堆这些设置的组合,但我希望有人能够揭示这种情况。

我还应该提及,我愿意使用.Net连接到远程桌面服务器的其他方法,如果有的话不涉及使用Microsoft Terminal Services Control Type Library。如果他们确实存在,我没有多少运气,但是请让我知道我是否在搜索时遗漏了任何东西。

编辑:为了确保自己的服务器设置相同或相似的矿只有两个需要满足的要求:

  1. 远程桌面必须在某个版本的Windows上运行即Vista或更高版本
  2. 远程桌面必须设置为使用NLA。在Win7中,确切的选项文本是:'仅允许从运行具有网络级身份验证(更安全)的远程桌面的计算机连接'

在那一点上我不在乎你在代码中更改了哪些选项,只要当您尝试连接并且证书框(或任何其他弹出窗口)从不出现在客户端时,服务器会记录失败的登录。

看来,添加此代码所需的适当引用的最简单方法是将“Microsoft终端服务控件”从“COM”选项卡添加到工具箱,然后将“Microsoft RDP客户端控件”拖放到表单上。点击此处了解详情:http://s.codeproject.com/Articles/43705/Remote-Desktop-using-C-NET

这是在C#中相同的代码的情况下,使这个问题更受欢迎:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     private AxMSTSCLib.AxMsRdpClient6NotSafeForScripting withEventsField_oRemote; 
     public AxMSTSCLib.AxMsRdpClient6NotSafeForScripting oRemote { 
      get { return withEventsField_oRemote; } 
      set { 
       if (withEventsField_oRemote != null) { 
        withEventsField_oRemote.OnAuthenticationWarningDismissed -= oRemote_OnAuthenticationWarningDismissed; 
        withEventsField_oRemote.OnAuthenticationWarningDisplayed -= oRemote_OnAuthenticationWarningDisplayed; 
       } 
       withEventsField_oRemote = value; 
       if (withEventsField_oRemote != null) { 
        withEventsField_oRemote.OnAuthenticationWarningDismissed += oRemote_OnAuthenticationWarningDismissed; 
        withEventsField_oRemote.OnAuthenticationWarningDisplayed += oRemote_OnAuthenticationWarningDisplayed; 
       } 
      } 
     } 
     private void Form1_Load(object sender, EventArgs e) 
     { 
      oRemote = new AxMSTSCLib.AxMsRdpClient6NotSafeForScripting(); 
      ((System.ComponentModel.ISupportInitialize)oRemote).BeginInit(); 
      oRemote.Dock = System.Windows.Forms.DockStyle.Fill; 
      oRemote.Enabled = true; 
      oRemote.Name = "OfficeWin7"; 
      this.Controls.Add(oRemote); 
      ((System.ComponentModel.ISupportInitialize)oRemote).EndInit(); 
      oRemote.CreateControl(); 
      oRemote.Size = new System.Drawing.Size(800, 600); 

      oRemote.Server = "IPADDRESS"; 
      oRemote.UserName = "TestAccount"; 
      oRemote.AdvancedSettings7.ClearTextPassword = "WrongPassword"; 

      MSTSCLib.IMsRdpClientNonScriptable4 ocx = (MSTSCLib.IMsRdpClientNonScriptable4)oRemote.GetOcx(); 

      ocx.EnableCredSspSupport = true; 
      ocx.AllowCredentialSaving = false; 
      ocx.PromptForCredentials = false; 
      ocx.PromptForCredsOnClient = false; 

      oRemote.Connect(); 
     } 

     private void oRemote_OnAuthenticationWarningDismissed(object sender, EventArgs e) 
     { 
      MessageBox.Show("The credentials popup is now closing"); 
     } 

     private void oRemote_OnAuthenticationWarningDisplayed(object sender, EventArgs e) 
     { 
      MessageBox.Show("The credentials popup is about to be shown"); 
     } 
     public Form1() 
     { 
      Load += Form1_Load; 
     } 
    } 
} 
+0

你不应该在另一个StackExchange网站上试试这个问题吗? –

+0

做了一个快速搜索,并且在另一个堆栈站点上看不到太多这种类型代码的其他示例。至少在这里有很多例子,但大多数都没有涉及到我的特殊问题。我很乐意提供有关发布该内容的其他建议,因为我的项目处于暂停状态,直到我可以解决此问题。 –

+0

也许我错了,但它可能值得在[服务器故障](http://serverfault.com/)上拍摄。现在,也许你会离题,但你永远不知道,因为我相信你的问题在SO和服务器故障之间...... –

回答

1

首先,你真的需要确保您的测试环境采用了最新的更新RDP特别是如果它是Windows 7 - 只需运行Windows Update。

接下来,专注于这一行:

ocx.EnableCredSspSupport = True 

它使一个安全支持提供商。我没有在这个问题上的专家,但有可能是一个内部例程说法:

Load locally stored credentials; if there aren't such - ask the user then crypt, hash, bla-bla, and store them locally, in order to use them next time

此时对话框,询问凭据被弹出。我不认为你可以影响这种行为,但幸运的是,你可以影响提供者是否在图片中发生。所以设置为False,看看会发生什么。

+0

Windows和其他Microsoft产品都已全部更新。'EnableCredSspSupport = true'是启用NLA支持的行。如果没有这个,你不能连接到运行NLA的'新'远程桌面实例 - 它只是拒绝连接。如果还有另外一种方法可以在不使用这条线的情况下在客户端上启用NLA支持,那么我就会全神贯注。 –

+0

@JoeyJoeJoeJrShabadoo:的确如此。但是你提到你可以影响服务器设置,对吧?你可以试试看,只是为了隔离问题......在服务器端禁用NLA。 –

+0

请阅读我的整个问题。我已经提到,当我禁用服务器上的NLA时,代码工作的很好。我的问题是,我想支持这两种类型的远程桌面连接,我试图让NLA方现在工作。它已经触发了像我想要的失败登录,但问题是这个代码旨在无人值守运行,凭证弹出让我搞砸了。 –