我需要将位于我的 newtwork 目录上的文件复制到我的本地计算机。我做了一些研究,发现了一个名为 Windows API 的函数,但是当我尝试调用复制文件时,我收到了拒绝访问的消息。这里是项目。
procedure TForm1.btnLoginLogOnClick(Sender: TObject);
var
phToken: THandle;
begin
WriteLog('');
WriteLog('Current user: ' + GetCurrentUser());
// check for correct login
phToken := 0;
try
phToken := CheckLogin(Edit1.Text, Edit2.Text, Edit3.Text); //user,password,domain
WriteLog('Handle: ' + IntToStr(phToken));
if (phToken > 0) Then begin
WriteLog('User login ok');
// login ok, switch ACL to new login context (demo purpose only)
ImpersonateLoggedOnUser(phToken);
WriteLog('Impersonated user: ' + GetCurrentUser());
if( CopyFile(PWideChar(Edit4.Text),('C:\cp2101.zip'),false)=false) then//CopyFile('c:\a.jpg','c:\warn.jpg',true))=false then
ShowMessage(SysErrorMessage(GetLastError));
// revert back to original login context
RevertToSelf;
WriteLog('Reverted to original user: ' + GetCurrentUser());
TQuery(phToken, Edit3.Text);
TQueryGroups(phToken, Edit3.Text);
end else begin
WriteLog('User login failed');
end;
finally
CloseHandle(phToken);
end;
end;
这是项目:项目链接