tags:

views:

281

answers:

2

I don't really understand windows UAC...

I need for my program to be able to update and add files to a specific directory belonging to a program. This directory may be a subdirectory of an application in Program Files, for example c:\Program Files\MyApp\Data or it may be installed elsewhere.

I believe that if it's under Program Files then my program will be prevented from writting there unless it is running as an administrator AND has elevated it's access rights. Is that correct?

I need to be able to update files in that directory preferable without invoking elevated privileges and with the main application still "protected", just allow access to that one directory. I can't move the Data folder elsewhere as this as it's a 3rd party application I need to interface with.

How is it determined that UAC is needed for folders in Program Files? Is Program Files special in some way or is just permissions? If I were to adjust the permissions on that Data subdirectory so that the user account running the program had write access would that allow my application to update files in that directory without special privileges?

Or is there a better way to achieve this that I'm not thinking of? My update program needs to be in java so getting elevated privileges is a pain. I imagine I'll need to write a C++ wrapper to run the java VM so that i can give that wrapper an appropriate manifest. Not impossible but I don't really want to have to do this.

+2  A: 

Try changing your application's directory security settings on-install to allow "Authenticated Users" write permissions.

DxCK
And this will work? That was really my question, is "bypassing" UAC for one directory as simple as changing the permissions on that directory?
John Burton
yes, adding write permission to "Authenticated Users" should work, at least it worked for me.
DxCK
Thanks, it gives me options. I do feel uncomfortable about changing the permissions though even though I'm only going to change them to what they would be if the folder was in the correct location.
John Burton
+1  A: 

Usually, when you need both protected and unprotected UAC modes you do the following.

  1. Create two executable (one should be the main one and not require privileges for any operation, the second one should be able to perform privileges operations).
  2. Start the first (main) one using limited privileges.
  3. When you need to perform an privileged operation, create a new process with administrative rights (will pop the UAC window) and start the second application in it.
  4. When done with the second application close it and you'll be back to limited mode.

This is how VMWare Workstation does when you change global settings.

Edit: Changing the permissions on a folder is not a good approach. Is just a dirty hack because anybody can write to that folder and this will just invalidate the role of UAC - after all this is the role of UAC: to prevent unprivileged changes in special folders.

Victor Hurdugaci
I don't feel in this case it's a dirty hack particularly. The application should have been designed to put the Data directory in the user's documents area, not under it's own program files so by granting write access to it there I'm not giving any permissions that a *good* design wouldn't have given - it's just not a good thing to encourage... At least that's my understanding.The problem I have with 2 executables is that this program needs to be in java so it's not a simple thing to do.The points are good though so +1, just not quite sure I can easily do that
John Burton
Accepted this as it's the correct answer I suppose even if it's not the answer I wanted :)
John Burton

related questions