Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 08-04-2010, 01:10 PM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Question User Full name query

I hope this is the right place to put this request.

I am putting together a form to assist people with filling out the form.
One of the items I need to be able to populate is the current users full name, which is linked to their userid. I can get Edit1.Text to show the userid, but how do I display the users full name?

We use Exchange server, as well as Active Desktop.
Unfortunately, I am not officially programming in the company, so I don't have info to access AD.
I am trying to display the name, without having to setup an TADOConnection.
Is it possible to use an active connection? The user must be logged into the domain to be able to use the PC, so...
The PC displays the logged in user's full name, but how is it able to do this? We connect to a domain name server.

I want to populate the form for the user but let the user be able to update the displayed info, but not the info on AD.
The info is copied to the clipboard and later pasted into another application.

I have no code to show as what I'm trying, as this is still very new to me and I'm on the design stage still, considdering it will be quite complex with many options and fields.

Further, I want to save some of this info to Setup.INI to display the custom info when the user opens the app. Some of this I can do. But still very complicated.

I have completed another project which works fine, however this one I just can't seem to find an answer.

Thanks in advance.
S
Reply With Quote
  #2  
Old 08-05-2010, 08:50 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

If you refer to the windows full username (stored at the server) you can use this (stripped) unit I wrote based on some internet samples I cannot recall anymore:
Code:
unit NetAPI32;

interface

uses
  Windows, SysUtils;

  function GetCurrentUser(): String;
  function GetDomainServerName(): String;
  function GetDomainFullName(ServerName, UserName: String): String;

implementation

  function NetUserGetInfo(ServerName, UserName: PWideChar; Level: DWORD; var Buffer: Pointer): DWORD; stdcall; external 'netapi32.dll' name 'NetUserGetInfo';
  function NetApiBufferFree(Buffer: pointer): DWORD; stdcall; external 'netapi32.dll' name 'NetApiBufferFree';
  function NetWkstaUserGetInfo(ServerName: PWideChar; Level: DWORD; var Buffer: Pointer): Longint; stdcall; external 'netapi32.dll' name 'NetWkstaUserGetInfo';

type
  TUserInfo1 = packed record
    UserName: PWideChar;
    DomainName : PWideChar;
    OtherDomainNames: PWideChar;
    ServerName: PWideChar;
  end;
  PUserInfo1 = ^TUserInfo1;

  TUserInfo2 = packed record
    Name: PWideChar;
    Password: PWideChar;
    PasswordAge: DWORD;
    Priv: DWORD;
    HomeDir: PWideChar;
    Comment: PWideChar;
    Flags: DWORD;
    ScriptPath: PWideChar;
    AuthorFlags: DWORD;
    FullName: PWideChar;
    UserComment: PWideChar;
    Params: PWideChar;
    WorkStations: PWideChar;
    LastLogon: DWORD;
    LastLogoff: DWORD;
    AccountExpires: DWORD;
    MaxStorage: DWORD;
    UnitsPerWeek: DWORD;
    LogonHours: DWORD;
    BadPasswordCount: DWORD;
    LogonCount: DWORD;
    Server: PWideChar;
    CountryCode: DWORD;
    Codepage: DWORD;
  end;
  PUserInfo2 = ^TUserInfo2;

function GetCurrentUser(): String;
var
  username: String;
  size: DWORD;
begin
  size := 255;
  SetLength(username, size) ;
  if GetUserName(PChar(username), size) then
    Result := Copy(username, 1, size - 1)
  else
    Result := '';
end;

function GetDomainServerName(): String;
var
  PUI1: PUserInfo1;
begin
  Result := '';
  if NetWkstaUserGetInfo(nil, 1, Pointer(PUI1)) = 0 then
  begin
    try
      Result := WideCharToString(PUI1^.ServerName);
    finally
      NetApiBufferFree(PUI1);
    end;
  end;
end;

function GetDomainFullName(ServerName, UserName: String): String;
var
  PUI2: PUserInfo2;
begin
  Result := '';
  if NetUserGetInfo(PWideChar(WideString(ServerName)), PWideChar(WideString(UserName)), 2, Pointer(PUI2)) = 0 then
    try
      Result := WideString(PUI2^.FullName);
    finally
      NetApiBufferFree(PUI2);
    end;
end;

end.
And call it like:
Code:
ShowMessage(GetDomainFullName(GetDomainServerName(), GetCurrentUser()));
Reply With Quote
  #3  
Old 08-05-2010, 09:12 AM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Thumbs up

Thank you very much for the quick response.
It worked like a charm.

Last edited by Shaun Hand; 08-05-2010 at 09:13 AM. Reason: Question has been answered!
Reply With Quote
Reply

Tags
ado, d2009, exchange server

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:09 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.