EdZava / VCL-ActiveDirectory4Delphi

Delphi basic library for validation and authentication of LDAP users in Active Directory.
MIT License
84 stars 15 forks source link

Constant crashes #1

Closed MHumm closed 2 years ago

MHumm commented 3 years ago

Trying the code below I get constant crashes with "The network path couldn't be found" failure. I'm using Delphi 10.4.1. I get them here: ActiveDirectoryClient.GetActiveDirectoryEnabled and here: Result := ActiveDirectoryClient.GetUserInfo(CurrentDomainName, CurrentUserName, outUserInfo);

The only things working without these crashes are: CurrentUserName := ActiveDirectoryClient.GetCurrentUserName; CurrentDomainName := ActiveDirectoryClient.GetCurrentDomainName(CurrentUserName);

Ok, my laptop is at home right now, so not in the company network, but it shouldn't crash I think. Here's my code:

`unit MainForm;

interface

uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type TForm1 = class(TForm) b_Test: TButton; m_Output: TMemo; procedure b_TestClick(Sender: TObject); private public end;

var Form1: TForm1;

implementation

uses ActiveDirectory.Client, ActiveDirectory.Types;

{$R *.dfm}

procedure TForm1.b_TestClick(Sender: TObject); var CurrentUserName: string; CurrentDomainName: string; CurrentLDAPDomainName: string; outUserInfo: TADSIUserInfo; Result : Boolean; begin // if (not ActiveDirectoryClient.GetActiveDirectoryEnabled) then // Exit;

CurrentUserName := ActiveDirectoryClient.GetCurrentUserName; CurrentDomainName := ActiveDirectoryClient.GetCurrentDomainName(CurrentUserName);

if ActiveDirectoryClient.GetUserActive(CurrentDomainName, CurrentUserName) then m_Output.Lines.Add('User active') else m_Output.Lines.Add('User not active');

Result := ActiveDirectoryClient.GetUserInfo(CurrentDomainName, CurrentUserName, outUserInfo);

CurrentLDAPDomainName := ActiveDirectoryClient.GetCurrentLDAPDomainName(CurrentDomainName);

m_Output.Lines.Add('CurrentUserName: ' + CurrentUserName); m_Output.Lines.Add('CurrentDomainName: ' + CurrentDomainName);

if Result then begin m_Output.Lines.Add('UID: ' + outUserInfo.UID); m_Output.Lines.Add('UserName: ' + outUserInfo.UserName); m_Output.Lines.Add('Description:' + outUserInfo.Description); m_Output.Lines.Add('Disabled:' + outUserInfo.Disabled.ToString(TUseBoolStrs.True)); m_Output.Lines.Add('Locked out:' + outUserInfo.LockedOut.ToString(TUseBoolStrs.True)); m_Output.Lines.Add('Groups:' + outUserInfo.Groups); end;

// m_Output.Lines.Add('CurrentLDAPDomainName: ' + CurrentLDAPDomainName); end;

end. `

EdZava commented 3 years ago

Thanks!

The readme example is pretty simple.

You can see a slightly more complete example of the application in the package example.

Look at the unit: TestActiveDirectory.View.Main.pas the method procedure TfrmMain.btnGetCurrentInfoClick (Sender: TObject);

You can compile and debug the example itself. Maybe this can help you more.

PS: But without the DA you will be able to do few things 😭.