Delphi / Rdp verifies username and password before connecting

as the subject says I'm trying to connect to the server using this code in delphi

procedure TmainF.Button1Click(Sender: TObject); var rdp1 : TMsRdpClient7NotSafeForScripting ; begin rdp1 := TMsRdpClient7NotSafeForScripting.Create(self); rdp1.Parent := mainF; rdp1.Server:=server_name; rdp1.UserName := user.Text; rdp1.AdvancedSettings7.ClearTextPassword := password.Text; rdp1.ConnectingText := 'connecting'; rdp1.DisconnectedText := 'disconnected'; rdp1.AdvancedSettings7.AuthenticationLevel:=0; rdp1.AdvancedSettings7.EnableCredSspSupport:=true; rdp1.Connect; end; 

the code works fine, but if the user entered an incorrect username or password
the rdp object displays a remote desktop prompt for re-entering a username or password, such as an image

enter image description here

I want to check the username and password before connecting or deny this field and show the user message from my application

I tried using OnLogonError (), but it did not run any code
and I read this Question , but the code is C # and I got confused with .getocx () and I can not find (PromptForCredentials) in (MSTSCLib_TLB.pas)

any help :( ??

Sorry for my bad english.

+2
source share
2 answers

There is an IMsRdpClientNonScriptable5 interface that has the following methods:

  • Get_AllowPromptingForCredentials()
  • Set_AllowPromptingForCredentials()

If you call Set_AllowPromptingForCredentials() with the parameter set to false , the dialog will not appear.

As for how to get an instance of this interface - it's simple, just enter the ControlInterface your RDP client object:

 Ircns5 := rdp1.ControlInterface as IMsRdpClientNonScriptable5; if Assigned(Ircns5) then Ircns5.Set_AllowPromptingForCredentials(False); 
+2
source

Before establishing a connection, you can pass the username and password to the Windows API " LogonUser " function. For this to work, the authentication object must be available on the user's network.

 {$APPTYPE CONSOLE} uses SysUtils, Windows; var hToken : THandle; begin if (ParamCount <> 3) then begin WriteLn ('LogonUserTest.exe [user name] [domain] [password]'); Halt ($FF); end; { if } try Win32Check (LogonUser (PChar (ParamStr (1)), PChar (ParamStr (2)), PChar (ParamStr (3)), Logon32_Logon_Interactive, LOGON32_PROVIDER_DEFAULT, hToken)); WriteLn ('LogonUser success'); CloseHandle (hToken); except on E: Exception do Writeln (E.ClassName, ': ', E.Message); end; { try / except } end. 
0
source

All Articles