I have created an application that writes some data to the root folder of the directory in which it was installed (in Program Files). But under Windows Vista, the program is unable to write to the directory because the UAC restricts administrative privileges.
I need to be able to do the following
- Write a file in the folder where the program was installed in program files.
That’s possible if the software is run with administrative privileges. But I don’t know how to modify my setup to always run it with administrative privileges.
Are there any ways or suggestions I can accomplish this?
It sounds like the title of your question asks how to make the installer run with administrative privileges but your explanation asks how to make the program run with administrative privileges so it can write to Program Files at runtime. Which one is it?
If you really just want the installer to run with administrative privileges, the community wiki answer is pretty accurate. Make sure your installer has an obvious name like ‘Setup.exe’ and Vista uses ‘heuristics’ to decide your installer must run as admin.
If you really want to write to Program Files at runtime, don’t. This is the official advice for Vista: write to the user’s AppData directory instead. If you have way too much code to rewrite, you can include a manifest file that forces Vista to prompt for administrative rights when running your app. If your app is named ‘app.exe,’ include a ‘app.exe.manifest’ file that contains the following: