我用函数 NetUserGetGroups 读取 “Guest” 的工作组为什么总是“None”??? (100分)

  • 主题发起人 主题发起人 paf
  • 开始时间 开始时间
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"

 
是不是guest禁用了?
 
真的没有人知道吗?
 
不是的,就算你是Administrator 也是不成
 
Guest是一个特殊的用户类型吧。
 
就算是别的用户也不成!
 
buffer应该用NetApiBufferAlloc分配内存,否则NetUserGetGroups调用出错
 
NetApiBufferAlloc 在哪里定义的?
 
需要自己定义:我写的不一定对,没试过
procedure NetApiBufferAllocate(size:dword;buffer:pchar);stdcall; external netapi32;
 
我加入 NetApiBufferAllocate 之后了错,要怎样搞啊!



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
NetApiBufferAllocate(1024,buffer); //要怎样加!!
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;

 
我这样写就行了,但返回错误2221
buffer:=allocmem(1024);
NetApiBufferAllocate(1024,buffer);
 
buffer:=allocmem(1024);
NetApiBufferAllocate(1024,buffer);

我把代码写入之后还是返回 None


 
我用Administrator作为组名执行函数返回值正确,所以,我觉得这个函数是不是只能
取在服务器端的组,对对等网的组无效啊,我这里没有2000服务器,没发试,你自己试
试吧
 
我插了一下帮助,只能获得全局组
The NetUserGetGroups function retrieves a list of global groups to which a specified user belongs.
 
那我要得到组信息,要怎样搞啊?
 
CBuilder的代码如下:
#include "lmaccess.h"
#include "lmerr.h"

DWORD entriesread, totalentries;
LOCALGROUP_USERS_INFO_0 *UInfo=NULL;
if(NetUserGetLocalGroups(NULL,L"Guest",0,LG_INCLUDE_INDIRECT,
(LPBYTE *)&UInfo,-1, &entriesread,&totalentries)==NERR_Success)
{
for (int i=0;i<entriesread;i++)
{
this->Memo1->Lines->Add(UInfo.lgrui0_name);
}
}

 
最好用活動目錄編程﹐這個才行的。我用C#做了一個﹐可以實現目錄的內容備份。
 
这里有个例子
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1206546
 
可不可以转为DELPHI代码啊!
 
后退
顶部