Attempted to perform an unauthorized operation - Error message on Delete a File

sanjoydas

New member
Joined
Nov 12, 2008
Messages
4
Programming Experience
3-5
Attempted to perform an unauthorized operation. - Error is showing on delete a File in Windows Vista OS. The following code is used with windows Application -
VB.NET:
Dim fInfo As New FileInfo("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\My Application.lnk")
Dim objSecId As Security.Principal.SecurityIdentifier
objSecId = Security.Principal.WindowsIdentity.GetCurrent.User
fInfo.GetAccessControl()
fSecurity.AddAccessRule(New Security.AccessControl.FileSystemAccessRule(objSecId, Security.AccessControl.FileSystemRights.Delete, Security.AccessControl.AccessControlType.Allow))
fInfo.SetAccessControl(fSecurity) 'UnauthorizedAccessException occurs here
fInfo.Delete()

Instead of above code using the following code -
VB.NET:
File.Copy(SourcePath,DestinationPath,True)
File.Delete(SourcePath) 'UnauthorizedAccessException occurs here

Now the Error is "Access to the Path 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\My Application.lnk' is Denied" is Showing in Windows Vista.

The user is of Tye Administrator in Windows Vista. The user having Permission of Read and Execute from OS of the Specific folder / File mentioned. I want to provide the User add Delete permission for the file mentioned above through code.

Please help how to resolve this.

Thanks in advance.:)
 
Last edited:

Latest posts

Back
Top