F
forza
Unregistered / Unconfirmed
GUEST, unregistred user!
以下两个过程分开做是没有问题的,但是如果写在一个procedure里就不可以了。
其中 NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
UserInfo总是nil,何故呀?
procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
aNetRes:TNETRESOURCE;
Error: DWord;
TimeOut:TimeVal;
begin
fillchar(aNetRes,sizeof(TNetResource),0);
anetRes.dwScope := RESOURCE_CONNECTED;
anetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
aNetRes.dwType := RESOURCETYPE_ANY;
aNetRes.lpLocalName := '';
aNetRes.lpProvider := '';
str:='//'+edit2.text+'/ipc$';
aNetRes.lpRemoteName :=pchar(str);
error := WNetAddConnection2(anetres,'','',0);
TimeOut.tv_sec:=2;
TimeOut.tv_usec:=0;
end;
procedure TForm1.Button3Click(Sender: TObject);
var str : string;
Userinfo : PUser_info_0;
servername : pwidechar;
netapiStatus, nStatus : longword;
lpbuffer : pointer;
counter : integer;
s:string;
begin
str := '//'+edit2.Text;
getmem(servername,sizeof(widechar)*(length(str)+1));
stringtowidechar(str,servername,sizeof(char)*(length(str)+1));
repeat
NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
for Counter := 0 to EntiesRead - 1 do
begin
//do something
Inc(UserInfo);
end;
freemem(servername);
NetApiBufferFree(lpBuffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
如果合在一起写的话就不行了:
procedure TForm1.Button1Click(Sender: TObject);
var
str,str1 : string;
aNetRes:TNETRESOURCE;
Error: DWord;
TimeOut:TimeVal;
Userinfo : PUser_info_0;
servername : pwidechar;
netapiStatus, nStatus : longword;
lpbuffer : pointer;
Counter : integer;
begin
fillchar(aNetRes,sizeof(TNetResource),0);
anetRes.dwScope := RESOURCE_CONNECTED;
anetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
aNetRes.dwType := RESOURCETYPE_ANY;
aNetRes.lpLocalName := '';
aNetRes.lpProvider := '';
str:='//'+edit2.text+'/ipc$';
aNetRes.lpRemoteName :=pchar(str);
error := WNetAddConnection2(anetres,'','',0);
TimeOut.tv_sec:=2;
TimeOut.tv_usec:=0;
if error = NO_ERROR then
begin
str1 := '//'+edit2.Text;
getmem(servername,sizeof(widechar)*(length(str1)+1));
stringtowidechar(str1,servername,sizeof(char)*(length(str1)+1));
repeat
NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
for Counter := 0 to EntiesRead - 1 do
begin
//do something as NetUserGetInfo
Inc(UserInfo);
end;
freemem(servername);
NetApiBufferFree(lpBuffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
end;
其中 NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
UserInfo总是nil,何故呀?
procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
aNetRes:TNETRESOURCE;
Error: DWord;
TimeOut:TimeVal;
begin
fillchar(aNetRes,sizeof(TNetResource),0);
anetRes.dwScope := RESOURCE_CONNECTED;
anetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
aNetRes.dwType := RESOURCETYPE_ANY;
aNetRes.lpLocalName := '';
aNetRes.lpProvider := '';
str:='//'+edit2.text+'/ipc$';
aNetRes.lpRemoteName :=pchar(str);
error := WNetAddConnection2(anetres,'','',0);
TimeOut.tv_sec:=2;
TimeOut.tv_usec:=0;
end;
procedure TForm1.Button3Click(Sender: TObject);
var str : string;
Userinfo : PUser_info_0;
servername : pwidechar;
netapiStatus, nStatus : longword;
lpbuffer : pointer;
counter : integer;
s:string;
begin
str := '//'+edit2.Text;
getmem(servername,sizeof(widechar)*(length(str)+1));
stringtowidechar(str,servername,sizeof(char)*(length(str)+1));
repeat
NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
for Counter := 0 to EntiesRead - 1 do
begin
//do something
Inc(UserInfo);
end;
freemem(servername);
NetApiBufferFree(lpBuffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
如果合在一起写的话就不行了:
procedure TForm1.Button1Click(Sender: TObject);
var
str,str1 : string;
aNetRes:TNETRESOURCE;
Error: DWord;
TimeOut:TimeVal;
Userinfo : PUser_info_0;
servername : pwidechar;
netapiStatus, nStatus : longword;
lpbuffer : pointer;
Counter : integer;
begin
fillchar(aNetRes,sizeof(TNetResource),0);
anetRes.dwScope := RESOURCE_CONNECTED;
anetRes.dwDisplayType := RESOURCEDISPLAYTYPE_SERVER;
aNetRes.dwType := RESOURCETYPE_ANY;
aNetRes.lpLocalName := '';
aNetRes.lpProvider := '';
str:='//'+edit2.text+'/ipc$';
aNetRes.lpRemoteName :=pchar(str);
error := WNetAddConnection2(anetres,'','',0);
TimeOut.tv_sec:=2;
TimeOut.tv_usec:=0;
if error = NO_ERROR then
begin
str1 := '//'+edit2.Text;
getmem(servername,sizeof(widechar)*(length(str1)+1));
stringtowidechar(str1,servername,sizeof(char)*(length(str1)+1));
repeat
NetApiStatus := NetUserEnum(serverName, 0, 0, lpBuffer, -1, EntiesRead, TotalEntries, ResumeHandle);
UserInfo := PUSER_INFO_0(lpBuffer);
for Counter := 0 to EntiesRead - 1 do
begin
//do something as NetUserGetInfo
Inc(UserInfo);
end;
freemem(servername);
NetApiBufferFree(lpBuffer);
until (NetApiStatus <> ERROR_MORE_DATA);
end;
end;