UnauthorizedAccessException Trying To Delete Start Menu Item Despite Running As Administrator


i'm trying use file.delete(path name) delete file in common start menu under windows 8.1. file shortcut (.lnk), although don't believe type of file matters. since it's file not folder, don't have worry nested content being removed first directory. in theory, there should no barriers. 

manipulating common start menu is, know, under uac; if try windows explorer running normally, twenty different prompts (i exaggerate; it's nineteen). 

my code running admin (by debugging instance of visual studio running admin, , have code confirm running in admin mode), in theory should remove problem - doesn't. unauthorizedaccessexception thrown. 

i've tried (a snippet found on related question): 

directorysecurity security = directory.getaccesscontrol(pathname); 

string identity = environment.userdomainname 

+ path.directoryseparatorchar 

+ environment.username ; 

filesystemaccessrule rule = new filesystemaccessrule(identity, 

filesystemrights.fullcontrol, 

accesscontroltype.allow);

security.addaccessrule(rule); 


on file , parent directories before trying delete them, no change. 

can suggest why still can't delete it, or how might find out problem is? 

thanks. 

hi,

do create shortcut file via code? if have created folder via code, folder's readonly attributes gets setup.in order delete code, 1 needs remove readonly attribute first. if not done,it throw unauthorized access exception. if have file inside folder readonly attribute, result in same exception:

file.setattributes(file, fileattributes.normal); file.delete(file);
best wishes!


we trying better understand customer views on social support experience, participation in interview project appreciated if have time. helping make community forums great place.
click here participate survey. thanks<br/> msdn community support<br/> <br/> please remember &quot;mark answer&quot; responses resolved issue. common way recognize have helped you, , makes easier other visitors find resolution later.



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'