0

My application writes to the registry in HKEY_LOCAL_MACHINE, so I use a manifest file to utilize the UAC functionality. Though when I write data to the users AppData folder (after the UAC dialog prompt appears) the data writes to the administrator's AppData folder, and not the current user's AppData folder. If I want to write the data to the correct path, how can I do that?

1 Answer 1

0

Is the current user who starts the application in Administrators group? You can also find it out by the look of the UAC prompt: if user is in Administrators group, the dialog is a simple confirmation: Yes or No; if user is not in Administrators group, then the dialog prompts for Administrator credentials: user name and password. (Screen shots of Consent UI and Credentials UI).

  1. User is in Administrators group
    Then after Yes button is clicked, the application is launched in context of the same user but with full administrator token enabled.
  2. User is not in Administrators group
    The after user types the administrators account name and the password, the application is launched in context of another user. Therefore all the user-specific settings will be written to that administrator user's registry and AppData rather than the user who initially started the application.

So if you want to write global settings to HKLM and local settings to the current user's profile, you have run elevated only the part which writes to HKLM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.