Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Вывести информацию о пользователях, подключенных к рабочей станции

Delphi , Интернет и Сети , Сеть

Вывести информацию о пользователях, подключенных к рабочей станции

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

type
   THostInfo = record
     username: PWideChar;
     logon_domain: PWideChar;
     other_domains: PWideChar;
     logon_server: PWideChar;
   end;

   WKSTA_USER_INFO_0 = packed record
     wkui0_username: PWideChar;
   end;
   PWKSTA_USER_INFO_0 = ^WKSTA_USER_INFO_0;

 implementation

 {$R *.dfm}

 function NetWkstaUserEnum(servername: PWideChar;
   // Pointer to a string that specifies the DNS or NetBIOS name of the 
  // remote server on which the function is to execute. 
  // If this parameter is nil, the local computer is used. 
  level: DWORD;
   // Level = 0 : Return the names of users currently logged on to the workstation. 
  var bufptr: Pointer;   // Pointer to the buffer that receives the data 
  prefmaxlen: DWORD;
   // Specifies the preferred maximum length of returned data, in bytes. 
  var entriesread: PDWord;
   // Pointer to a value that receives the count of elements actually enumerated. 
  var totalentries: PDWord;  // total number of entries 
  var resumehandle: PDWord)
   // contains a resume handle which is used to continue an existing search 
  : Longint;
   stdcall; external 'netapi32.dll' Name 'NetWkstaUserEnum';


 function EnumNetUsers(HostName: WideString {; Users: TStrings}): THostInfo;
 const
   STR_ERROR_ACCESS_DENIED = 'The user does not have access to the requested information.';
   STR_ERROR_MORE_DATA = 'Specify a large enough buffer to receive all entries.';
   STR_ERROR_INVALID_LEVEL = 'The level parameter is invalid.';
 var
   Info: Pointer;
   ElTotal: PDWord;
   ElCount: PDWord;
   Resume: PDWord;
   Error: Longint;
   // UI : PWKSTA_USER_INFO_0; 
  // i : Integer; 
begin
   Resume := 0;
   NetWkstaUserEnum(PWideChar(HostName),
     1,
     Info,
     0,
     ElCount,
     ElTotal,
     Resume);

   Error := NetWkstaUserEnum(PWideChar(HostName),
     1,
     Info,
     256 * Integer(ElTotal),
     ElCount,
     ElTotal,
     Resume);

   case Error of
     ERROR_ACCESS_DENIED: Result.UserName := STR_ERROR_ACCESS_DENIED;
     ERROR_MORE_DATA: Result.UserName     := STR_ERROR_MORE_DATA;
     ERROR_INVALID_LEVEL: Result.UserName := STR_ERROR_INVALID_LEVEL
       else
         if Info <> nil then
         begin
           Result := THostInfo(info^);
     { 
    To retrieve all users: 
    UI := PWKSTA_USER_INFO_0(Info); 
    for i := 1 to DWord(ElCount) do 
    begin 
      Users.Add(UI^.wkui0_username); 
      inc(UI); 
    end; 
    }
         end
         else
           begin
             Result.UserName      := 'N/A';
             Result.logon_domain  := 'N/A';
             Result.other_domains := 'N/A';
             Result.logon_server  := 'N/A';
           end;
   end;
 end;


 procedure TForm1.Button1Click(Sender: TObject);
 var
   HostInfo: THostInfo;
 begin
   // Specify target machine as argument (with or without preceding \\) 
  HostInfo := EnumNetUsers('WORKSTATION');
   with HostInfo do
   begin
     Memo1.Lines.Add(username + #13#10+
      logon_domain + #13#10+
      other_domains + #13#10+
      logon_server);
   end;
 end;

Статья Вывести информацию о пользователях, подключенных к рабочей станции раздела Интернет и Сети Сеть может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: Сеть ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100
20.04.2024 18:55:21/0.0033669471740723/2