title: delphi, windows impersonation as user to copy a file
body: <p>I need to copy a file located on a directory on my newtwork to my local machine. I did some research and i found a function called Windows API, but when I tried to call copy file I received an access denied message. 
  Here is the project.</p>
  
  <pre><code>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 &gt; 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;
  </code></pre>
  
  <p>this is the project: <a href="https://mega.co.nz/#!45RnXa6D!eYsaVBHBAkpq6sK8-ARCyR5ev8QQO2PoeOGTNdP_UmY" rel="nofollow">Project link</a></p>