如果仅是用远程机的用户名和密码来删除足够权限的文件,可以参考下面
如果想做远程管理,最好还是在服务器端放个被控制程序才方便。
procedure TForm1.Button1Click(Sender: TObject);
const
RemoteShareName='//192.168.0.1/d$'; //必须共享或默认共享
var
NetResource : TNetResource;
begin
with NetResource do
begin
dwScope:=RESOURCE_GLOBALNET;
dwUsage:=RESOURCEUSAGE_CONNECTABLE;
dwType:=RESOURCETYPE_DISK;
dwDisplayType:=RESOURCEDISPLAYTYPE_SERVER;
lpLocalName:='z:';
lpRemoteName:=RemoteShareName;
lpProvider:='';
end;
if WnetAddConnection2(NetResource,'远程密码','远程用户名',CONNECT_UPDATE_PROFILE)<>NO_ERROR then
raiselastwin32error;
DeleteFile('z:/test.txt');
if WNetCancelConnection2('z:',CONNECT_UPDATE_PROFILE,True)<>NO_ERROR then
RaiseLastWin32Error;
showmessage('ok');
end;