tags:

views:

359

answers:

3

I need to write to some files in the application directory which is installed under Program Files. I know that with UAC enabled on Vista and Windows 7, users can't modify files in this directory. However, I'm aware of the UAC Virtualization that was added in Vista which basically redirects writes to the virtualstore directory . In Vista this works great and my files are actually written to this virtualstore directory. However, on Windows 7 I am getting access denied errors and my files are not written to this directory at all. What gives?

+1  A: 

I'm not sure what you are trying to do, but you should not be writing data in the program files directory unless you are upgrading or modifying the application itself.

I would change the code to write to the correct location. The Vista redirect was just a kludge to keep applications from breaking.

Always use the Environment.GetFolderPath method to get system paths.

Dana Holt
I realize that it is not totally correct behavior to be writing to the program files directory, I will fix this in a future release, but I am just trying to come up with a stop-gap fix. I don't see why the behavior is different between Vista and 7.
Jason
@Jason - I see, then Henk's answer would be appropriate.
Dana Holt
A: 

Is it the exact same binary or was it re-compiled (under Win7)?

If your app's manifest indicates that it is Vista-aware than Vista would also give an error.

Henk Holterman
This is the same binary that was used on both Vista and 7.
Jason
Ah, oops, I just double-checked and I noticed that I had changed the application to use the default manifest settings. I just rebuilt it without any manifest and the virtualstore kicked in. Thanks.
Jason
Hmm, I just noticed another strange thing. When I use the binary on a 32 bit Win7 machine it works fine (when built with no manifest). However, when I put it on a Win7 64 bit machine I get access denied errors again. Is it possible that Win7 64 bit enforces the vista-aware behavior? I just tried it on Vista 64 bit and I have no problems there...
Jason
Ok, just figured it out. I had to build the assembly as x86 instead of any cpu. There are a bunch of conditions that control the virtualization. Here is some more info on that: http://social.msdn.microsoft.com/Forums/en-CA/vcgeneral/thread/9bb7a71c-d284-4c18-ac7b-a40eb21ea671
Jason
A: 

Have you tried to use IsolatedStorageFile?

Gopher