Access denied when using Directory.Move() in impersonation with UserLogon with Interactive

时间:2016-12-02 05:30:12

标签: windows

When I try to perform Directory.Move() I get error

System.IO.IOException ... Access Denied

Steps to reproduce:

  1. Run Visual Studio 2013 at console with PsExec.exe -s -d -i which could assign system privilege to my program. (When running System.Security.Principal.WindowsIdentity.GetCurrent().Name gives NT AUTHORITY\\SYSTEM)
  2. LogonUser with LOGON32_LOGON_INTERACTIVE and invoke ImpersonateLoggedOnUser() - no error returned
  3. Directory.Move(myfolderAtProgramData,myfolderAtProgramData+"_")
  4. VS throws a System.IO.IOException - 'Access Denied'

If LogonUser with LOGON32_LOGON_NEW_CREDENTIALS then it works. Why??

Below are references for my implementation:

  1. What is the difference: LoadUserProfile -vs- RegOpenCurrentUser
  2. Impersonation to get user HKEY_CURRENT_USER does not work?
  3. Access CurrentUser Registry Key for Impersonated User - Compatibility with .NET 3.5
  4. https://social.msdn.microsoft.com/Forums/vstudio/en-US/fd531413-1ea9-4141-bba8-c1c5e9270001/access-currentuser-registry-key-for-impersonated-user-compatibility-with-net-35?forum=csharpgeneral

Environment:

Win10 Pro 64bit ,EN ,Visual Studio 2013 , .Net4.0 , c#
A folder at ProgramData (allow modification only with administrator privilege)

0 个答案:

没有答案
相关问题