Problem writing to users AppData directory
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开发者_如何学C, how can I do that?
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).
- 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. - 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.
精彩评论