Solved

userlist

Posted on 1997-05-11
6
165 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 304
Virtuailstring tree compare node issue 14 117
Run video youtube webbrowse 10 62
Sending files from  idTcpServer Socket to idTcpClient 2 40
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 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