2

as the subject say am trying to connect to 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 is working fine but if the user entered a wrong user name or password
the rdp object is showing the remote desktop login prompt box to reenter the user name or password like the image

enter image description here

I want to validate the username and password before connect
or prevent this box and show a custom message from my app

I tried to use OnLogonError() procedure but it's not fired any code
and I read this Question but the code is c# and I confused with .getocx() and I can't find (PromptForCredentials) in (MSTSCLib_TLB.pas)

any help :( ??

sorry for my bad English.

4

2 回答 2

2

有一个接口IMsRdpClientNonScriptable5具有以下方法:

  • Get_AllowPromptingForCredentials()
  • Set_AllowPromptingForCredentials()

如果您Set_AllowPromptingForCredentials()使用设置为对话框的参数进行调用,false则不会出现。

至于如何获取此接口的实例 - 很简单,您只需转换ControlInterface您的 RDP 客户端对象:

Ircns5 := rdp1.ControlInterface as IMsRdpClientNonScriptable5;
if Assigned(Ircns5) then
  Ircns5.Set_AllowPromptingForCredentials(False);
于 2017-11-27T19:16:23.007 回答
0

您可以在建立连接之前将用户名和密码传递给 Windows API 函数“ LogonUser ”。为此,身份验证实体必须在用户的网络上可用。

{$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.
于 2017-11-27T21:34:50.987 回答