Since the release of Win Vista, Microsoft introduced file virtualization for legacy applications running as 32bit processes. Released as part of Microsoft's User Account Control (UAC) any legacy applications attempting to write to any locations considered protected by the operating system are redirected to the VirtualStore.
At this point, steps have been taken to ensure that the application in question now runs as a 64bit process that is UAC aware, however, this does little to address the issue of migrating the users data to a location that is considered safe from virtualization.
While troubleshooting this issue, I've found that when dealing with multiple user accounts some changes have been made within the legacy path located at C:\Program Files(x86)\MyApp\Data
while at the same time, changes have been made to the VirtualStore located at %localappdata%\VirtualStore\Programs\MyApp\Data
. The question being, how can I detect if any file/folder virtualization is taking place and how can I merge the two locations?
EDIT: I found several websites that detail the problem and how to duplicate it, but nothing that includes a way to fix it. I did find this reference FILE_ATTRIBUTE_VIRTUAL that defines a file attribute that seems promising – I found another reference somewhere, though I can't remember where, that states that this is the attribute used by Windows to indicate that file virtualization is taking place and flags the request for redirection.
These links describe the issue:
http://www.c-sharpcorner.com/uploadfile/GemingLeader/windows-file-and-registry-virtualization/
http://www.codeproject.com/Articles/66275/Windows-Vista-File-and-Registry-Virtualization
Best Answer
Wasn't easy, but I found how to detect whether UAC virtualization is enabled. Calling
GetTokenInformation()
and passing inTokenVirtualizationEnabled
as the information class will return whether file and registry virtualization is enabled. Here is a C function to do it:A bit harder with P/Invoke, but here it is, including the P/Invoke headers:
I tried turning UAC virtualization on and off with Task Manager and verified that the correct result is returned. Enabling and disabling virtualization can be done by calling
SetTokenInformation()
.Microsoft says they plan on removing UAC virtualization in a future Windows version and for programs to not rely on it existing. I saw a suggestion by someone to make a separate program that is not UAC aware to move files from the VirtualStore to AppData, but I don't know if that's a good solution or not.