?
Solved

NT - Using Delphi to Extract Username *AND* Full Name

Posted on 1999-07-22
5
Medium Priority
?
460 Views
Last Modified: 2010-04-04
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(GetUserNameArray, 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
0
Comment
Question by:iwatkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1390372
Simply call NetUserGetInfo with e.g. level 1.
If you have questions, please ask me...

Regards, Madshi.
0
 

Author Comment

by:iwatkins
ID: 1390373
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
0
 
LVL 20

Accepted Solution

by:
Madshi earned 800 total points
ID: 1390374
Hi Ian,

do something like this:

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 TUserInfo1  = packed record
                     name         : PWideChar;
                     password     : PWideChar;
                     password_age : dword;
                     priv         : dword;
                     home_dir     : PWideChar;
                     comment      : PWideChar;
                     flags        : dword;
                     script_path  : PWideChar;
                   end;
     TPUserInfo1 = ^TUserInfo1;

function GetUserComment(servername,username: string) : string;
var ui1 : TPUserInfo1;
begin
  result:='?';
  if NetUserGetInfo(pwidechar(wideString(servername)),pwidechar(wideString(username)),1,pointer(ui1))=0 then
    try
      result:=wideString(ui1^.comment);
    finally NetApiBufferFree(ui1) end;
end;

Regards, Madshi.

0
 

Author Comment

by:iwatkins
ID: 1390375
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(wideString(servername)),pwidechar(wideString(username)),2,pointer(ui2))=0 then
    try
      result:=wideString(ui2^.full_name);
    finally NetApiBufferFree(ui2) end;
end;


0
 
LVL 20

Expert Comment

by:Madshi
ID: 1390376
Thanx for the extras...   :-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question