Solved

userlist

Posted on 1997-05-11
6
168 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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