Search code examples
delphidelphi-2009windows-7-x64

Windows 7 - Displaying "Access denied" message when user tries to save file to a protected folder rather than save in virtual store


We want to restrict files being saved to the virtual store in Vista/Windows 7 if the user tries to save files from our application to a protected folder such as "Program files" - we want an "Access Denied" message displayed if the user tries to do this. Is there a way to do this from our Delphi 2009 app similarly to what MS Word etc. do?.

Thanks very much,

Paul


Solution

  • If you make your application "UAC aware", Windows will disable registry and file virtualization for your application. The OS will then return errors if your application tries to write to a protected area and the process does not have elevated admin rights.

    You can do this by adding a manifest that requests a requestedExecutionLevel. There are numerous articles online that describe this process. Here are a couple of good ones:

    Making Your Application UAC Aware http://www.codeproject.com/KB/vista-security/MakingAppsUACAware.aspx

    UAC Virtualization – Allowing standard users to update a system protected area http://blogs.technet.com/b/mrsnrub/archive/2010/08/11/uac-virtualization-allowing-standard-users-to-update-a-system-protected-area.aspx