When I try to perform Directory.Move() I get error
System.IO.IOException ... Access Denied
Steps to reproduce:
- Run Visual Studio 2013 at console with
PsExec.exe -s -d -iwhich could assign system privilege to my program. (When runningSystem.Security.Principal.WindowsIdentity.GetCurrent().NamegivesNT AUTHORITY\\SYSTEM) - LogonUser with LOGON32_LOGON_INTERACTIVE and invoke
ImpersonateLoggedOnUser()- no error returned Directory.Move(myfolderAtProgramData,myfolderAtProgramData+"_")- 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:
- What is the difference: LoadUserProfile -vs- RegOpenCurrentUser
- Impersonation to get user HKEY_CURRENT_USER does not work?
- Access CurrentUser Registry Key for Impersonated User - Compatibility with .NET 3.5
- 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)