0

I'm creating Revit add-in, the add-in deletes files from C:\ProgramData\Autodesk\Revit\Addins\2017 folder on Revit startup. I'm using impersonation to copy, rename and delete files using the admin credentials.

The problem is when I start the Revit as administrator, it works perfectly. but when starting normally, it won't work and throws this System.UnauthorizedAccessException: Access to the path is denied.

  • 1
    So what is your problem exactly? – Mihir Dave Mar 06 '18 at 13:36
  • If it's ok for your application to always run as administrator then have a search for how to run your application as an administrator (somebody has posted below). Otherwise, I'm afraid you don't have permission to access this – LordWilmore Mar 06 '18 at 13:40
  • I need to delete files located in that directory, but I don't want to start Revit as admin because users of Revit don't have admin privileges. – Ahmed Habib Mar 06 '18 at 13:40
  • check out System.Security.Permissions.FileIOPermission. You might get around it if you "permission.Demand()" FileIOPermissionAccess.AllAccess. You'll need to get a FileInfo for each file in the directory, and demand each one. – Aaron Mar 06 '18 at 14:00

1 Answers1

0

This might help you.

Add into your project Application Manifest File (Add -> New Item -> General -> Application Manifest File) and add the below node into the app.manifest:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx

Mihir Dave
  • 3,954
  • 1
  • 12
  • 28