c# - Prevent failed logon attempt window after failing to supply proper credentials to a remote desktop server using Network Level Authentication -
i using 'microsoft terminal services control type library' establish connection remote desktop server. looking way prevent or suppress 'windows security' prompt displayed when failing provide proper username/password combination when connecting remote desktop server uses network level authentication (nla). window looks this:
i have read , tried every combination of settings can find online @ time , none of them have been successful. here couple of questions found on stackoverlow talk exact issue , supposedly resolved answers not working me:
axmsrdpclient9 dismiss login dialog
axmsrdpclient6notsafeforscripting allowpromptingforcredentials
it may sound ridiculous ultimate goal attempt connecting rdp server , purposely enter invalid username/password , disconnect when fails. not care connecting or displaying anything. if matters, doing in attempt trigger failed logon attempt in event logs on remote server app make use of later.
the code below triggers failed logon attempt in event logs cannot find way stop failed logon box popping on client machine , rather not resort hacks attempt close window after open. when remote desktop server configured allow connections computers running version of remote desktop (less secure option) not have same problem popup prompt part of security nla offers.
i have tried many different combinations of settings control head spinning. here 1 example modeled after 1 of other stackoverflow questions above:
public class form1 dim withevents oremote axmstsclib.axmsrdpclient6notsafeforscripting private sub form1_load(sender object, e 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 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 object, e eventargs) handles oremote.onauthenticationwarningdismissed messagebox.show("the credentials popup closing") end sub private sub oremote_onauthenticationwarningdisplayed(sender object, e eventargs) handles oremote.onauthenticationwarningdisplayed messagebox.show("the credentials popup shown") end sub end class
supposedly ocx.promptforcredentials = false
line should prevent popup doesn't seem make difference if value set true
or false
. assume property name ocx.promptforcredsonclient
might work, again, doesn't make difference set value to. same popup.
at point have no idea doing wrong gut tells me working need instantiate base axmsrdpclient6notsafeforscripting
object else axmsrdpclient9notsafeforscripting
or axmstscaxnotsafeforscripting
default type control uses when drop onto form. have tried bunch of these combinations of settings , hoping can shed light on situation.
i should mention open alternative methods of connecting remote desktop server using .net don't involve using microsoft terminal services control type library
if there any. didn't have luck finding them if exist please let me know if missed in search.
edit: ensure own server set same or similar mine there 2 requirements need met:
- remote desktop must running on version of windows vista or newer
- remote desktop must set use nla. in win7 exact option text is: 'allow connections computers running remote desktop network level authentication (more secure)'
at point don't care options change in code long server logs failed login when attempt connect , credentials box (or other popups) never appear on client side.
it appears easiest way add proper references code needs add 'microsoft terminal services control' com tab toolbox , drop 'microsoft rdp client control' onto form. more information here: http://s.codeproject.com/articles/43705/remote-desktop-using-c-net
here same code in c# in case makes question more popular:
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 { { 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 closing"); } private void oremote_onauthenticationwarningdisplayed(object sender, eventargs e) { messagebox.show("the credentials popup shown"); } public form1() { load += form1_load; } } }
first off, need make sure test environment uses latest update rdp, if it's windows 7 - run windows update.
next, focus on line:
ocx.enablecredsspsupport = true
it enabling a security support provider. i'm not expert in matter, there internal routine saying:
load locally stored credentials; if there aren't such - ask user crypt, hash, bla-bla, , store them locally, in order use them next time
at point dialog, asking credentials popped up. don't think can influence behavior, but, fortunately can influence whether provider takes place in picture or not. set false
, see happens.