api - delphi, windows impersonation as user to copy a file -


i need copy file located on directory on newtwork local machine. did research , found function called windows api, when tried call copy file received access denied message. here project.

procedure tform1.btnloginlogonclick(sender: tobject); var    phtoken: thandle; begin    writelog('');    writelog('current user: ' + getcurrentuser());    // check correct login    phtoken := 0;    try    phtoken := checklogin(edit1.text, edit2.text, edit3.text); //user,password,domain    writelog('handle: ' + inttostr(phtoken));    if (phtoken > 0) begin       writelog('user login ok');        // login ok, switch acl 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             showmessage(syserrormessage(getlasterror));        // revert original login context       reverttoself;       writelog('reverted original user: ' + getcurrentuser());        tquery(phtoken, edit3.text);       tquerygroups(phtoken, edit3.text);     end else begin       writelog('user login failed');    end;           closehandle(phtoken);    end; end; 

this project: project link

the first suggestion not have permissions access network directory, or file in question. these access permissions or copy permissions (or both). check have permissions both of these.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -