I'm in charge of maintaining a VB6 app and I've encountered an odd behavior on Windows 7.
When the application is installed to Program File (x86) (or I assume any directory it doesn't have write permissions to), most of the time, when it goes to save a file locally, it ends up in that weird Virtual Store place. This is acceptable. But occasionally, it will try to save locally and give an error saying you aren't allowed to save here, and asking if you'd like to save somewhere else. Well, at least, that's what it does if you try to save it as a new file, if you try to save it as an existing file it crashes with run-time error 75.
Both files are simply opened with "Open filename As #1" -- can anyone give me more information on what forces it to use, or not use, the Virtual Store in the folders that the user doesn't have permission to write to?
Alternatively, I tried running the application as Administrator, and it crashes on start-up, -- haven't figured out why a program would work in locked down mode and not as Administrator yet.
Well, you have pretty much figured it out yourself: to some locations you cannot write without elevation, to others not at all. For some locations Windows will come to the rescue and redirect the file to the VirtualStore. Among these are:
It think it is good programming practice to never assume that file operations will work without error. You can anticipate on errors and warn the user beforehand and you must embed any file operation in an
On Error Goto
block.About the program crashing when it is run elevated (this is really the solution of last resort, try to avoid this): The problem with the VirtualStore is that you can end up with two versions of a file: the one written when elevated and the one written when not elevated. When you run the program elevated it suddenly uses other files than before and thus can exhibit other behaviour, including crashes. The same thing applies to registry keys.
More over UAC Virtualization (excellent article!)
Good luck!