Solved

userlist

Posted on 1997-05-11
6
162 Views
Last Modified: 2010-04-06
Hi I have a NT Server.
And I would like to get a user list of who's logon
is there any api cal that will return this information

0
Comment
Question by:colonna
6 Comments
 
LVL 2

Accepted Solution

by:
javiertb earned 50 total points
Comment Utility
Yes, there's one called NetUserGetInfo.

NET_API_STATUS
NetUserGetInfo (

    LPWSTR servername,      
    LPWSTR username,      
    DWORD level,      
    LPBYTE * bufptr      
   );

Look up API help for more information.
0
 
LVL 2

Expert Comment

by:gysbert1
Comment Utility
I had a quick look at this but couldn't quickly find how this works in the help. Javiertb, I think you owe him some more details ;^)

So you propose that he runs through all the users on the system and check if each of them is logged in. This might take some time ... HMMMM I am sure there must be a better way out there somewhere to do this ...
0
 
LVL 2

Expert Comment

by:javiertb
Comment Utility
No,that wasn't my propose. Just a little missunderstanding. What I think you should use is the function NetUserEnum.

Hope this works.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:sperling
Comment Utility
javiertb: Read the god damn question before you answer it.

NetUserGetInfo retrieves arbitrary information about a user account.

NetUserEnum is used to enumerate the users which have an account on a given computer.

To retrieve a list of who is currently logged on to the server, use the delphi function below. It uses functions from the MS port of the LAN Manager functions, therefore it will only run under NT, not windows 95. You can query any NT computer using this function.

-----
type
  PWkstaUserInfo0 = ^TWkstaUserInfo0;
  TWkstaUserInfo0 =
    record
      username    : PWideChar;
    end;
  PWkstaUserInfo0Array = ^TWkstaUserInfo0Array;
  TWkstaUserInfo0Array = ARRAY [0..0] of TWkstaUserInfo0;

function NetWkstaUserEnum
  (ServerName : PWideChar;
  level       : DWORD;
  buffer      : POINTER;
  prefmaxlen  : DWORD;
  var
    EntriesRead,
    TotalEntries,
    ResumeHandle   : DWORD) : INTEGER; stdcall;
    external 'NETAPI32.DLL';

function NetApiBufferFree
  (Buffer : POINTER) : INTEGER; stdcall;
  external 'NETAPI32.DLL';


procedure GetLoggedOnUsers (Server : STRING; Users : TStrings);
var
  ui0        : PWkstaUserInfo0Array;
  wcServer   : ARRAY [0..MAX_PATH] OF WIDECHAR;
  Ndx,
  Error,
  EntriesRead,
  EntriesTotal,
  ResumeHandle   : DWORD;

begin
  ResumeHandle := 0;
  StringToWideChar(Server, wcServer, MAX_PATH);
  repeat
    Error := NetWkstaUserEnum
      (wcServer, 0, @ui0, 10000,
      EntriesRead, EntriesTotal, ResumeHandle);

    if (Error<>0) and (Error <> ERROR_MORE_DATA) then begin
      NetAPIBufferFree(ui0);
      raise Exception.CreateFmt('NetWkstaUserEnum failed with error #%d', [Error]);
    end;

    for Ndx := 0 to EntriesRead-1 do
      Users.Add(WideCharToString(ui0^[ndx].username));

    NetAPIBufferFree(ui0);
  until EntriesRead=EntriesTotal;
end;
-----

To test this thing, create a form with a button, a editbox and a listbox, and create this OnClick handler:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Listbox1.Clear;
  GetLoggedOnUsers(Edit1.Text, Listbox1.Items);
end;

Then, type the name of any NT computer in the edit, click the button and the Listbox will fill with the login names of the logged on users on the computer. Note that this function will not return the names of users which has connected to shares on the computer, as these are not logged on to the computer, but rather to the domain.

If this does what you need colonna, please reject javiertb's answer and allow me to submit this. Or better even, reject javiertb anyway, because his answer has nothing to do with what you've asked.

javiertb: Why can't you start reading the questions, work out an answer and then when you know it works, submit it. You're just being annoying when you keep providing bad and often plain incorrect answers.


Regards,

Erik.
0
 

Author Comment

by:colonna
Comment Utility
OK  what else do you need to know?
0
 

Author Comment

by:colonna
Comment Utility
OK you guys seem to work this out so  thanks again


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now