P
paf
Unregistered / Unconfirmed
GUEST, unregistred user!
const
netapi32 = 'netapi32.dll';
function NetUserGetGroups(servername, username: PWideChar; level: Cardinal; var bufptr: Pointer;
prefmaxlen: Cardinal; var entriesread, totalentries: Cardinal): LongInt; stdcall; external netapi32;
procedure GetUserGroups(const ServerName, UserName: string; Groups: TStrings);
var
ServerNameW, UserNameW: WideString;
Buffer: Pointer;
NetResult: Integer;
Read, Total: Cardinal;
I: Integer;
P: PGroupUsersInfo;
begin
Groups.BeginUpdate;
try
Groups.Clear;
ServerNameW := ServerName;
UserNameW := UserName;
NetResult := NetUserGetGroups(PWideChar(ServerNameW), PWideChar(UserNameW), 0, Buffer,
MAX_PREFERRED_LENGTH, Read, Total);
case NetResult of
ERROR_SUCCESS, ERROR_MORE_DATA:
begin
try
P := Buffer;
for I := 0 to Read - 1 do
with P^ do
begin
Groups.Add(grui0_name);
Inc(P);
end;
finally
NetApiBufferFree(Buffer);
end;
end;
else
raise Exception.CreateFmt('NetUserGetGroups error: %d', [NetResult]);
end;
finally
Groups.EndUpdate;
end;
end;
为什么返回的值总是"None"
netapi32 = 'netapi32.dll';
function NetUserGetGroups(servername, username: PWideChar; level: Cardinal; var bufptr: Pointer;
prefmaxlen: Cardinal; var entriesread, totalentries: Cardinal): LongInt; stdcall; external netapi32;
procedure GetUserGroups(const ServerName, UserName: string; Groups: TStrings);
var
ServerNameW, UserNameW: WideString;
Buffer: Pointer;
NetResult: Integer;
Read, Total: Cardinal;
I: Integer;
P: PGroupUsersInfo;
begin
Groups.BeginUpdate;
try
Groups.Clear;
ServerNameW := ServerName;
UserNameW := UserName;
NetResult := NetUserGetGroups(PWideChar(ServerNameW), PWideChar(UserNameW), 0, Buffer,
MAX_PREFERRED_LENGTH, Read, Total);
case NetResult of
ERROR_SUCCESS, ERROR_MORE_DATA:
begin
try
P := Buffer;
for I := 0 to Read - 1 do
with P^ do
begin
Groups.Add(grui0_name);
Inc(P);
end;
finally
NetApiBufferFree(Buffer);
end;
end;
else
raise Exception.CreateFmt('NetUserGetGroups error: %d', [NetResult]);
end;
finally
Groups.EndUpdate;
end;
end;
为什么返回的值总是"None"