I\'m writing a C# Windows application to update a .ini file for a legacy application. I don\'t have the source for the legacy application, so I cannot modify it.
The
Under UAC, applications with no UAC manifest that try to do things UAC prevents are subject to virtualization. This writes to a mirror location instead of the protected location. When you try to read, if there is a file in the mirror location, you get that file. In this way your app will work, even though it was written contradictory to the best practices of the time.
To find the mirror location, open a Windows explorer to the folder and look for a button in the toolbar that says Compatibility Files:
Perhaps this is enough for you - now that you know where to look you can trust virtualization and the app will work properly. If not, consider putting an external manifest on the application. A manifest saying asInvoker
will prevent virtualization and the writes will fail. If the app has error handling (like falling back to another location) perhaps this is good. A manifest saying requireAdministrator
will prevent virtualization and the writes will succeed. However the UAC consent will probably annoy your users.
(The image, btw, is from a blog entry of mine that talks a bit more about virtualization. http://www.gregcons.com/KateBlog/FindingFilesYoureSureYouWrote.aspx)
I find with many apps, a single run as administrator gets my settings in place and after that I can run without elevating. In that case train your users to right-click, run as administrator.
This started with Vista to increase security. If an app tries to write to a location that is protected (like ini files written to the app's folder under ProgramFiles, or to the Windows folder, the app's reads and writes to that file are redirected to a folder in C:\Users{username}\AppData\Local\VirtualStore\
the values are written but to some "mirror" file which resides somewhere else - that is part of the magic performed under the hood to not break legacy apps while still making a more secure OS... see http://technet.microsoft.com/en-us/library/dd837644%28WS.10%29.aspx