Home » Questions » Computers [ Ask a new question ]

Strange, possible "shadow copy" issue where two editors show different contents

Strange, possible "shadow copy" issue where two editors show different contents

I have some code that is reading a config file, but when I open the file in TextPad, I see different values than my application does. I checked it with Notepad. Notepad agrees with my application, TextPad shows something else.

Asked by: Guest | Views: 185
Total answers/comments: 1
Guest [Entry]

"You're probably running into a part of Vista's UAC features called Virtual Store. Here's a snippet from the article:

When an application writes to a system
location only writeable by
administrators, Windows then writes
all subsequent file operations to a
user-specific path under the Virtual
Store directory, which is located at
%LOCALAPPDATA%\VirtualStore. Later,
when the application reads back this
file, the computer will provide the
one in the Virtual Store. Because the
Windows security infrastructure
processes the virtualization without
the application’s assistance, the
application believes it was able to
successfully read and write directly
to Program Files. The transparency of
file virtualization enables
applications to perceive that they are
writing and reading from the protected
resource, when in fact they are
accessing the virtualized version.

Your application is running in a non-elevated (non-admin) context. So when it tries to open the file in the Program Files folder, that request is getting redirected to your user accounts Virtual Store location transparently. Your copy of TextPad is probably running in an elevated context and so it is seeing the file that lives in the real Program Files folder.

If this is your code that you can change the functionality of and you want users to be able to use it without running as admin, you should change the location of where you store your config files to somewhere in the user's ApplicationData folder where it belongs. Writing settings to a config file stored in the application's installation folder is highly discouraged these days. If you really have settings that should be applying to all users on the machine, you should write them to the All Users Application Data folder instead. And even then, you'll still have to run the app in an Elevated context by default unless you explicitly grant the Users group write access to your folder.

Just keep this mantra going in your head as you write software for Vista and beyond. ""Users can only write to their profile...Users can only write to their profile"""