Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

userlist

Posted on 1997-05-11
6
Medium Priority
?
172 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 100 total points
ID: 1336132
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
ID: 1336133
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
ID: 1336134
No,that wasn't my propose. Just a little missunderstanding. What I think you should use is the function NetUserEnum.

Hope this works.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:sperling
ID: 1336135
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
ID: 1336136
OK  what else do you need to know?
0
 

Author Comment

by:colonna
ID: 1336137
OK you guys seem to work this out so  thanks again


0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

876 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