I have a WPF app that creates some text files in its own install directory. However, even after the UAC prompt, windows vista and windows 7 users often times still get "file access failed" type errors. The solution is to find the executable in windows explorer and open up the compatibility tab under the file properties and check "run as administrator". This is obviously a terrible user experience but I'm not sure how to ensure the app can secure itself these permissions without that step being taken. I am not trying to bypass the UAC prompts.
Asked
Active
Viewed 4,279 times
2 Answers
2
In general, .Net wants you to put application generated files either into the user's home directory or the shared user folder. Have a look at this answer: When using a Settings.settings file in .NET, where is the config actually stored? It talks about .Net config files but you can put other files there.

Community
- 1
- 1

Maximilian Csuk
- 584
- 1
- 6
- 21
-
1thank you but I disagree with .net here. The reason being that the file location will change based on windows versions which creates a bit of a support nightmare given that my users are constantly creating and sharing files. It's so much easier to direct them to c:\program files\myapp\etc than to say "if xp then" – Ready Cent Feb 09 '11 at 14:47
-
2But you are aware that the Program files directory is not fixed either, aren't you? It changes with 64/32 bit systems, languages, ... and the install directory itself is of course changeable as well. But whatever fits you best... :-) – Maximilian Csuk Feb 09 '11 at 16:43
1
You can force your app to start with admin rights (UAC will show it's dialog box anyway) by embedding custom manifest (project properties -> build -> Manifest).
Manifest example (requestedExecutionLevel
part is importaint):
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="yourappname.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
</asmv1:assembly>

max
- 33,369
- 7
- 73
- 84