iwatkins
asked on
NT - Using Delphi to Extract Username *AND* Full Name
Hi All,
I am writing an application that as part of the output prints the details of the user who printed it.
I have no problem getting the username (I.e. the string that the user has to type in before their pasword) but I would like to get the Full Name.
To explain:
Under NT if you fire up User Manager and add a new user there are 5 boxes you fill in:
1. Username
I can get this with:
S := SizeOf(GetUserNameArray);
GetUserName(GetUserNameArr ay, S);
frmMain.txtUserName.Text := GetUserNameArray;
2. Full Name
3. Description
4. Pasword
5. Confirm Password
So, what I am after is some code (probably an API thing?) to get Full Name and Description of the currently logged in user.
Hope that makes sense.
Cheers
Ian
I am writing an application that as part of the output prints the details of the user who printed it.
I have no problem getting the username (I.e. the string that the user has to type in before their pasword) but I would like to get the Full Name.
To explain:
Under NT if you fire up User Manager and add a new user there are 5 boxes you fill in:
1. Username
I can get this with:
S := SizeOf(GetUserNameArray);
GetUserName(GetUserNameArr
frmMain.txtUserName.Text := GetUserNameArray;
2. Full Name
3. Description
4. Pasword
5. Confirm Password
So, what I am after is some code (probably an API thing?) to get Full Name and Description of the currently logged in user.
Hope that makes sense.
Cheers
Ian
ASKER
Madshi,
Found it!! I can read all about it in WIN32.hlp but I have tried using NetGetUserInfo in a Delphi program but the compiler complains that the:
'identifier NetUserGetInfo hasn't been declared'
Ok, must be in on of the rtl files that haven't been included in this app. But I have searched the full source tree only to not find the delphi wrapper to this function.
I have never come across this before, so how do I use this function directly ? Example code would be good.
Cheers
Ian
Found it!! I can read all about it in WIN32.hlp but I have tried using NetGetUserInfo in a Delphi program but the compiler complains that the:
'identifier NetUserGetInfo hasn't been declared'
Ok, must be in on of the rtl files that haven't been included in this app. But I have searched the full source tree only to not find the delphi wrapper to this function.
I have never come across this before, so how do I use this function directly ? Example code would be good.
Cheers
Ian
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Madshi,
Perfect. Works a treat.
Also managed to get the Full name too, see code below.
Nice one, thanks for the help. Now I know how to access other win32 stuff not covered by the wrappers. Hence a few extras for you.
Cheers
Ian
----------------------
function NetUserGetInfo(servername, username: PWideChar; level: dword; var buf: pointer) : dword; stdcall;
external 'netapi32.dll' name 'NetUserGetInfo';
function NetApiBufferFree(buf: pointer) : dword; stdcall;
external 'netapi32.dll' name 'NetApiBufferFree';
type TUserInfo2 = packed record
name : PWideChar;
password : PWideChar;
password_age : dword;
priv : dword;
home_dir : PWideChar;
comment : PWideChar;
flags : dword;
script_path : PWideChar;
auth_flags : dword;
full_name : PWideChar;
usr_comment : PWideChar;
parms : PWideChar;
workstations : PWideChar;
last_logon : dword;
last_logoff : dword;
acct_expires : dword;
max_storage : dword;
units_per_week : dword;
logon_hours : dword;
bad_pw_count : dword;
num_logons : dword;
logon_server : PWideChar;
country_code : dword;
code_page : dword;
end;
TPUserInfo2 = ^TUserInfo2;
function GetUserFullName(servername ,username: string) : string;
var ui2 : TPUserInfo2;
begin
result:='?';
if NetUserGetInfo(pwidechar(w ideString( servername )),pwidech ar(wideStr ing(userna me)),2,poi nter(ui2)) =0 then
try
result:=wideString(ui2^.fu ll_name);
finally NetApiBufferFree(ui2) end;
end;
Perfect. Works a treat.
Also managed to get the Full name too, see code below.
Nice one, thanks for the help. Now I know how to access other win32 stuff not covered by the wrappers. Hence a few extras for you.
Cheers
Ian
----------------------
function NetUserGetInfo(servername,
external 'netapi32.dll' name 'NetUserGetInfo';
function NetApiBufferFree(buf: pointer) : dword; stdcall;
external 'netapi32.dll' name 'NetApiBufferFree';
type TUserInfo2 = packed record
name : PWideChar;
password : PWideChar;
password_age : dword;
priv : dword;
home_dir : PWideChar;
comment : PWideChar;
flags : dword;
script_path : PWideChar;
auth_flags : dword;
full_name : PWideChar;
usr_comment : PWideChar;
parms : PWideChar;
workstations : PWideChar;
last_logon : dword;
last_logoff : dword;
acct_expires : dword;
max_storage : dword;
units_per_week : dword;
logon_hours : dword;
bad_pw_count : dword;
num_logons : dword;
logon_server : PWideChar;
country_code : dword;
code_page : dword;
end;
TPUserInfo2 = ^TUserInfo2;
function GetUserFullName(servername
var ui2 : TPUserInfo2;
begin
result:='?';
if NetUserGetInfo(pwidechar(w
try
result:=wideString(ui2^.fu
finally NetApiBufferFree(ui2) end;
end;
Thanx for the extras... :-)
If you have questions, please ask me...
Regards, Madshi.