Wednesday, December 20, 2017

DELPHI - How reconnect to another OS user - (AD account)

This example shows how to reconnect to other active directory user (with possibility to change domain).
var
  token : THandle;

  sApp_ReconnectUser_NewOSUser : string;
  sApp_ReconnectUser_NewOSDomain : string;
  sApp_ReconnectUser_NewOSPassword : string;
begin
  ...
  if not LogonUser( pchar( sApp_ReconnectUser_NewOSUser ), 
                    pchar( sApp_ReconnectUser_NewOSDomain ),
                    pchar( sApp_ReconnectUser_NewOSPassword ), 
                    LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, 
                    token ) then RaiseLastOSError;
  if not ImpersonateLoggedOnUser( token ) then
    begin
      ShowMessage( 'Reconnect problem.' );
      Application.Terminate;
    end;
  ...

No comments:

Post a Comment