简体   繁体   中英

Writing to configuration file in Program Files folder

Yes, I know I'm not supposed to do this. But the configuration file in question belongs to a windows service. My program provides the user with a UI for editing some of the settings. The service looks for the file in its directory. I can't change it.

For Windows 7, does UAC automatically prompt the user when I try to write the configuration file, or is there some coding I have to do to make UAC prompt?

Tony

I ended up writing a second program that is launched by my main program to actually write the configuration settings.

My main program checks the version of Windows. If it's not version 6 or higher, it just writes the configuration file. If it is 6 or higher, it writes the configuration file to a temporary file. Next, it launches the configuration save program, passing the name of the temporary file and the name of the file in the program folder as parameters.

The second program has the necessary manifest file settings to get it to request elevated privilege if UAC is on. So as it starts, you get the UAC dialog. If you say yes, the program runs and it copies the data from the temporary file to the actual configuration file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM