NetUserGetLocalGroups - 如何调用它? [英] NetUserGetLocalGroups - how to call it?

查看:21
本文介绍了NetUserGetLocalGroups - 如何调用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Delphi 2010,JEDI WinAPI 和 Windows 安全代码库 (WSCL) 的最新版本(来自存储库).

I am using Delphi 2010, latest version (from repository) of JEDI WinAPI and Windows Security Code Library (WSCL).

我不知道如何调用 NetUserSetGroups 函数.我这样做的方式是抛出异常:

I don't know how to call the NetUserSetGroups function. The way I am doing it, it is throwing an exception:

地址 5B8760BE 的访问冲突在模块netapi32.dll"中.写的地址 00000000.

Access violation at address 5B8760BE in module 'netapi32.dll'. Write of address 00000000.

以下是我的代码:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JwaWindows, JwsclSid;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  NetApiStatus: NET_API_STATUS;
  dwEntriesRead, dwEntriesTotal: PDWORD;
  lgi01: LOCALGROUP_USERS_INFO_0;
  username: PChar;
begin
  username := 'Elise';

  NetApiStatus := NetUserGetLocalGroups(nil, PChar(username), 0, LG_INCLUDE_INDIRECT, PByte(lgi01),
    MAX_PREFERRED_LENGTH, dwEntriesRead, dwEntriesTotal);
  if NetApiStatus = NERR_SUCCESS then
    showmessage('Total groups user belongs to: ' + IntTostr(dwEntriesTotal^));

end;

end.

如果有人能告诉我如何调用这个函数,我将不胜感激?

Would appreciate if someone could kindly show me how I can call this function?

提前致谢.

推荐答案

这段代码很适合我:

type
  LocalGroupUsersInfo0Array = array[0..ANYSIZE_ARRAY-1] of LOCALGROUP_USERS_INFO_0;
  PLocalGroupUsersInfo0Array = ^LocalGroupUsersInfo0Array;

procedure TForm3.Button3Click(Sender: TObject);
var
  nas: NET_API_STATUS;
  PLGUIA: PLocalGroupUsersInfo0Array;
  Count: DWORD;
  Total: DWORD;
  i: Integer;
begin
  PLGUIA := nil;
  nas := NetUserGetLocalGroups(nil, PChar('rweijnen'), 0, LG_INCLUDE_INDIRECT,
    PByte(PLGUIA), MAX_PREFERRED_LENGTH, @Count, @Total);

  if (nas =  NERR_Success) or (nas = ERROR_MORE_DATA) then
  begin
    for i := 0 to Count - 1 do
    begin
      Memo1.Lines.Add(Format('name=%s', [PLGUIA^[i].lgrui0_name]));
    end;

    if Assigned(PLGUIA) then
      NetApiBufferFree(PLGUIA);
  end;
end;

这篇关于NetUserGetLocalGroups - 如何调用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆