Link to home
Start Free TrialLog in
Avatar of jfreisen
jfreisen

asked on

Get network username

I am using Delphi 3 on a Novell network. How do I get the name of the user logged in?
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Epsylon
Epsylon

procedure TForm1.Button1Click(Sender: TObject);
var name: array[0..63] of Char;
    size: Cardinal;
begin
  size := 64;
  if GetUserName(@name, size) then
    ShowMessage(name);
end;

it's almost the same, but i prefer dynamically allocating and disposing the buffer...

function GetUserName: string;
var
  dwSize: DWord;
  p: PChar;
begin
  dwSize := 1024;
  p := StrAlloc(Succ(dwSize));
  if GetUserName(p, dwSize) then
    Result := StrPas(p)
  else begin
    Result := 'none';
    GetLastError;
  end;
  StrDispose(p);
end;

regards,

BlackDeath.

function TForm1.GetMyNetUserName: string;
begin
   SetLength(Result, dbiMaxUserNameLen + 1);
   Check(DbiGetNetUserName(PChar(Result)));
   SetLength(Result, StrLen(PChar(Result)));
end;

Epsylon,
I tried to send you an email and it came back.  We are doing a survey of our top 100 experts to find out what improvements they would like at the site.  Please send me an up-to-date email address.

Linda Gardner
Customer Service @ Experts Exchange
linda@experts-exchange.com