共享目录的名称:test
物理路径:D:\test
程序如下:
type
PShare_Info_2 = ^TSHARE_INFO_2;
TSHARE_INFO_2 = record
shi2_netname: PWideChar;
shi2_type: DWORD;
shi2_re: PWideChar;
shi2_permissions: DWORD;
shi2_max_uses: DWORD;
shi2_current_uses: DWORD;
shi2_path: PWideChar;
shi2_passwd: PWideChar;
End;
function NetShareGetInfo(ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer) : Integer;stdcall;external 'netapi32.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
ShInfo: PShare_Info_2;
lError: DWord;
shareName:String;
shareNames:WideString;
begin
new(ShInfo);
shareName:='test';
shareNames:=shareName;
lError :=NetSharegetInfo(nil,PChar(shareNames),2,Pointer(ShInfo));
showmessage(inttostr(lError));
showmessage(WideCharToString(ShInfo.shi2_path));
end;
end.
运行结果:iError=0,证明已经执行成功,但是ShInfo.shi2_path为空,不知道什么原因,
请指点.
物理路径:D:\test
程序如下:
type
PShare_Info_2 = ^TSHARE_INFO_2;
TSHARE_INFO_2 = record
shi2_netname: PWideChar;
shi2_type: DWORD;
shi2_re: PWideChar;
shi2_permissions: DWORD;
shi2_max_uses: DWORD;
shi2_current_uses: DWORD;
shi2_path: PWideChar;
shi2_passwd: PWideChar;
End;
function NetShareGetInfo(ServerName : PChar; NetName : PChar; ShareLevel : SmallInt; Buffer : Pointer) : Integer;stdcall;external 'netapi32.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
ShInfo: PShare_Info_2;
lError: DWord;
shareName:String;
shareNames:WideString;
begin
new(ShInfo);
shareName:='test';
shareNames:=shareName;
lError :=NetSharegetInfo(nil,PChar(shareNames),2,Pointer(ShInfo));
showmessage(inttostr(lError));
showmessage(WideCharToString(ShInfo.shi2_path));
end;
end.
运行结果:iError=0,证明已经执行成功,但是ShInfo.shi2_path为空,不知道什么原因,
请指点.
谢谢你的指点,按你的方法我试了下问题依旧
好使了,改了下定义:function NetShareGetInfo(ServerName : PWideChar; NetName : PWideChar; ShareLevel : DWORD;var Buffer : Pointer) : Integer;stdcall;external 'netapi32.dll';
Buffer前加了var,这样才执行成功的
但新的问题出现了,改为远程路径出现错误码5.查了下是拒绝访问,我想是权限问题,这个在msdn里已留意到了,
怎么才能用管理员权限的用户去执行netsharegetinfo这个指点,请指点.
詳細資料,參考 http://msdn.microsoft.com/en-us/library/bb525388(VS.85).aspx注意Re部分,里面介紹了,此函數可應用的范圍。再比對你那邊的環境看看....