Solved

userlist

Posted on 1997-05-11
6
164 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 210
ddeman not working in activex 3 93
creating threads in delphi 1 82
Delphi and Access based Enumeration 9 46
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

20 Experts available now in Live!

Get 1:1 Help Now