Folder Virtualization in Windows Vista
So I may have been a little hasty yesterday when talking about restrictive file access rights in Windows Vista. As it turns out there’s a mechanism that’s supposed to be able to work around these issues and it’s called folder virtualization.
The issue is that if you install into Program Files and you run as a non-admin account you won’t have write access to the files in your install folder. This is obviously a common thing for many applications that store their configuration data there as well as data.
I personally have always preferred installing data in a central location instead of plastering files all over your hard-drive which is what DLL and directory hell are all about. Nothing cleaner than a single directory install, right? Well, Vista doesn’t like it at least if you plan to run with a non-admin account.
So earlier today when I tried this virtualization did not work and that’s why I was having so much trouble with getting permission errors. I mucked around with my security policy setting (with gpedit.msc) a bunch and it’s possible that I enabled that feature and it’s disabled by default. I don’t know maybe somebody can check.
What this feature does is this: It detects any write access to a file by a user that doesn’t have rights to write to this file. It then makes a copy of the file in the user’s virtual store and happily allows the user to write to the file in the virtualized directory where the user has full rights.

What you see in this image are all the files that the application wrote to and made changes to which were then virtualized in this directory. The original files stay in the Program Files install folder.
That’s an impressive piece of architecture if you think about it, and it’s going to solve some problems with applications not having enough rights. It’s also useful for applications that never played well with multiple users – when turned on you get automatic user data separation for free.
Kinda confusing though. So I’m running Html Help Builder and it uses an INI file for a number of configuration settings. So I write out the config settings by saving from the Config dialog but the data doesn’t go into the .ini file in the install directory but the one in the virtual store. So if you ever look at the file in Program Files you're not going to see the same setting that the user just wrote.
Now if I log in as Administrator in turn though I do have rights to read the file from the original directory and now when I save it saves to program files. If I change the permissions in the program files directory and allow the non-admin user access to write it’s going to the Program Files directory again and it’s potentially shared. Looks like if the file exists in both locations the private virtualized location is used.
Brrrr… cool, but it can get confusing. So if you do want to share files in a single path for all users you have to be specific about it and give the appropriate users rights. Same if you want to share files over the network, but I suppose in that case a directory off the root is probably a better place for shared data.
Also as I mentioned yesterday the problem with WinZip actually turned out to be a problem with the WinZip self extractor which has lost its original command line interface. Once I ran the old version 2.x the Html Help Builder update (which is live now BTW for those of you that use Html Help Builder) worked.
As to installation I had to switch to an Admin user to install the application. For some reason Vista would not allow me to elevate to an Administrator in the existing session so I had to switch to my admin account, install, then come back and run Html Help Builder. I’m happy to report that once installed Html Help Builder ran Ok including building the help file and doing .NET imports (which is always a little tricky in terms of security).
I’m making headway, but I’m still a long way from getting this all dialed right. I’m not sure what the proper approach is for application installation and locations. I’ve been browsing around some of the Microsoft documents and they tell you a lot about what happens but not a lot about recommended approaches. <shrug>.
The Voices of Reason
# re: Folder Virtualization in Windows Vista
I have used your Web Connect product for several years. I have a lot of respect for your thoughts on things. I have run into a problem with my application that was built using VFP 8.0 in which I distribute certain .vcx files which are shared between the VFP apps that comprise the application so that I don't have to include them in each project that uses them. These .vcx files are stored with the app files in a subfolder of the Program Files directory.
Because of the underlying way in which VFP opens these files when a class is used, they are automatically being virtualized in Windows Vista even though NOTHING is being written to them. Obviously this will cause problems in deploying future updates to the program as the class libraries that have been virtualized will not be updated.
I want to be able to turn off virtualization for my application in Vista. I have tried including an external application manifest file with a requestedExecutionLevel of "asInvoker". This does not disable virtualization of the libraries even though the Microsoft documentation says that it will. I have also attempted to embed the application manifest into my VFP executable using the mt.exe tool that ships with Visual Studio 2005. This appears to complete successfully, but the resulting executable is no longer recognized as a VFP file.
Do you have any information that can help me get past this problem? I’m supposed to leave on a ski trip on Friday and I know I’ll enjoy it a lot more if I am past this problem. I suppose that I could just require that the application files for my application be installed outside any of the Windows folders for which virtualization occurs, but not allowing my application files to be installed under the Program Files folder just seems wrong. Thoughts?
Thanks.
Florence Durant
# re: Folder Virtualization in Windows Vista
I've been having a problem trying to get more than local folders to show up in Vista when using the VFP function GETDIR() or using BrowseForFolder method of the Shell object. Have you encountered this issue and if so, do you know of solution. The exact same code works as expected in Win2K and WinXP. I'm assuming the issue may be along the same lines you mentioned in this post or some type of permissions issue.
Thanks in advance for any light you might be able to shed on this issue. :-)
James
# re: Folder Virtualization in Windows Vista
# re: Folder Virtualization in Windows Vista
#define BIF_BROWSEFORCOMPUTER 0x1000
#define BIF_BROWSEFORPRINTER 0x2000
#define BIF_BROWSEINCLUDEFILES 0x4000
#define BIF_BROWSEINCLUDEURLS 0x80
#define BIF_DONTGOBELOWDOMAIN 0x2
#define BIF_EDITBOX 0x10
#define BIF_NEWDIALOGSTYLE 0x40
#define BIF_NONEWFOLDERBUTTON 0x200
#define BIF_NOTRANSLATETARGETS 0x400
#define BIF_RETURNFSANCESTORS 0x8
#define BIF_RETURNONLYFSDIRS 0x1
#define BIF_SHAREABLE 0x800
#define BIF_STATUSTEXT 0x4
#define BIF_UAHINT 0x100
#define BIF_USENEWUI 0x40
#define BIF_VALIDATE 0x20
local loShell,loFolder,lcFolder,lnFlags
declare integer GetActiveWindow in Win32API
lcFolder = ''
lnFlags = BIF_NEWDIALOGSTYLE + BIF_NONEWFOLDERBUTTON + BIF_UAHINT
loShell = CreateObject('Shell.Application')
loFolder = loShell.BrowseForFolder(GetActiveWindow(),'Please Select Network Folder',lnFlags)
if vartype(loFolder) = 'O'
lcFolder = loFolder.Items.Item.Path
endif
release loShell
loShell = null
release loFolder
loFolder = null
return lcFolderI really just want the user to select a folder, not a file. If I use GetFile(), is there a way to select just a folder?
Thanks for any insight into this issue you may have.
James
# re: Folder Virtualization in Windows Vista
Last night, I was messing around with the directory selection dialog (both VFP flavor and Win32API flavor) and found out if I mapped a drive letter to a created network share (not the default network share such as \\SERVER\c$\Some Folder), that the mapped drive letter actually showed up in the dialog. YAHOO! Making some progress. So, as long as there is a Network share (which all of my network installations call for anyway), and you map a drive letter to that share or folder under that share, the mapped drive letter displays in the dialog. So, at least for me, this issue has been resolved. Threw me because I was testing orignally on a Windows XP machine where all the mapped drive letters that I created displayed no matter if I connected to the default share or not. When I tried the same thing in Vista, they would not show. Finally, decided to map a drive letter to an existing share on my network and the drive letter now displays in the dialog.
Hope this helps somebody else out there.
Thanks,
James
# re: Folder Virtualization in Windows Vista
I think you can always make this work with the FileOpen dialog box which allows you to specify whether to display network shares, but it's more work to make that behave for directories...
# re: Folder Virtualization in Windows Vista
All the best!
James
# re: Folder Virtualization in Windows Vista
# re: Folder Virtualization in Windows Vista
Everything is workable with the exception of the auto-update mechanism. That I cannot make work in program files so currently I check for the ability to write files in the local app path, and if not prompt users to quit the app and run the app again by Run as Administrator. This is obviously nothing as smooth as an auto-update, but it it's not huge hassle either.
# re: Folder Virtualization in Windows Vista
# re: Folder Virtualization in Windows Vista
For updates - the updates have to go into Program Files (or wherever the app was installed) hence the message to require Admin Privileges.
Remember too that if you need to set permissions for a shared file location ANYWAY you might as well change thepermissions in your specifc Program files folder. You can even do that during setup by executing CACLS or other utility to set permissions. You could install your app and add a special folder to the app and add open permissions to that folder by adding the EveryOne or Authenticated Users group... that might allow working around all of this although this goes against the Windows guidelines. But screw that - if you have data you have to share you have data you need to share <s> - there are no two ways around it.
# re: Folder Virtualization in Windows Vista
I just finished LUA certification of one of my own products tonight - I'm in the trenches with you!
To make your auto-update feature work better than telling the user to execute your app with 'runas', sequester the auto-update functionality in a COM object, which can allow on-demand elevation via the COM elevation moniker. The COM object will have write access to your binaries.
Info on the particulars of the COM object are here: http://developersoven.blogspot.com/2007/02/leveraging-vistas-uac-with-delphi-part_3659.html
If updating in your app can also be instigated by the user, put the shield on command widget so that the user knows they are going to be asked for elevation when you instantiate the COM object.
For the uninteractive update process, it should be made minimally interactive, at least to the degree that the user is told that you are about to lauch the auto-updating process, which may require authentication.
Good night, and good luck.
Ross
# re: Folder Virtualization in Windows Vista
My solution was to move shared data to a subdirectory of the location specified by the 'AppData' value in HKLM\...\Shell Folders. Typically, this resolves to C:\Documents and Settings\All Users\Application Data\ in XP, and C:\ProgramData\
Create your <AppName> subdir, and mark it writable by the Everyone account. For some finesse, put your shared-but-write-once in that directory, but make a separate directory for writable shared data e.g. ...\<AppName>\Shared
Now, if all files are present at install, just change the permissions on the files, not the directory, which is more security-conscious.
In any case, these are better approaches than opening up the directory permissions within your C:\Program Files\<AppName> directory or subdirectory. It makes it easier to prevent abuse of your binaries, and makes any network admins less jittery (their policies may allow limited user writing to the Machine's AppData but not Program Files).
Your alternative of creating a new C:\ root folder won't solve your problem - only the creating user or the Admin Group will have permission to write to that folder.
# re: Folder Virtualization in Windows Vista
# re: Folder Virtualization in Windows Vista
I have a problem with Virtualization. I have a file (config.ini) in c:\program files\app name\dat folder. I have to share this file with the other users ("standard" users). What are the ways to achieve this? I will install this application as admin but while running they are standard users.
Thanks,
Shreenivas
# re: Folder Virtualization in Windows Vista
I have some queries regarding virtualization.There is utility secpol.msc in which they have given that user account control can be enabled or disabled.Problem am facing is if I install an application with Administrator then it installs in C:\Program Files but if am writing some files through my application then it writes to the virtual folder.I need to write program which enables or disables this virtualization so that when my installed application writes some files then it will write in installed path only and not in the virtual folder.
Can you help out for this?
Thanks,
Trupti
# re: Folder Virtualization in Windows Vista
What I've experimentally determined is that I can create a sub-folder (within Program Files) with a specified DACL. That is, if I use the sample code from MSDN for CreateMyDACL (http://msdn2.microsoft.com/en-us/library/ms717798.aspx), then I can create a folder within Program Files that all authenticated users are able to read AND write to.
I'm thinking of using this, but it kinda worries me to use it in a production application.
I'm looking for feedback.
# re: Folder Virtualization in Windows Vista
In fact I did that with Help Builder a while back - I ran with low permissions, then switched UAC off and all of a sudden all my configuration settings were not there anymore because it's reading from another location. That's been fixed since, but it's something to consider.
Yes you can use your installer to create a directory (anywhere pretty much) where common files can be stored, but this is not appropriate according to the Windows guidelines. If you do that you should use the Program Files Common folder or create a completely separate data folder somewhere.
# re: Folder Virtualization in Windows Vista
You are right, creating a folder within "Program Files" would be a violation of the guidelines.
On a somewhat related note, have you (or anyone else) figured out a way to determine if the path for a new file will be virtualized to the VirtualStore when UAC is turned on?
Thanx,
-Az
# re: Folder Virtualization in Windows Vista
Applications installed into the /Program Files/ folder but where to put common data such as a database or config information where all users will be reading/writing the same data.
using SHGetSpecialFolderPath to get CSIDL_COMMON_APPDATA kinda sounds like it ought to get me a common appdata folder but, for normal users, in vista that still gets virtualized. d'oh!
Additionally, if the application wanted to 'hide' something such as a license code, trial expiry information etc, where would this be stored so that all users are using the same license, trial counters ?
When microsoft made Vista did it not occur to them that different users of the same computer might actually need to co-operate and share data ??
# re: Folder Virtualization in Windows Vista
# re: Folder Virtualization in Windows Vista
Florence wrote:
>not allowing my application files to be installed under the Program Files folder
> just seems wrong
If you are sure that you want to install your application into C:\Program Files\ProductName\...
and write into HKEY_LOCAL_MACHINE\Software\ProductName registry key
then you can do these two things:
a) provide a manifest file with your application where you mention level="asInvoker"
b) provide a manifest file with your installer (or a separate helper EXE) where you mention level="asInvoker". Then give your installer (or a separate helper EXE) the ability to grant the 'Users' group write access into the C:\Program Files\ProductName\ and into the HKEY_LOCAL_MACHINE\Software\ProductName registry key
To achieve b), prepare yourself to write some Win32 API code
Look into MSDN for the functions GetNamedSecurityInfo(), GetAce(),LookupAccountSid(),
SetEntriesInAcl() and SetNameSecurityInfo(). A nice tool with source code to get some inspiration from, is the AccessEnum tool
Binary here:
http://www.microsoft.com/technet/sysinternals/Security/AccessEnum.mspx
Source code
http://web.archive.org/web/20060427234047/http://www.sysinternals.com/Files/AccessEnumSource.zip
# re: Folder Virtualization in Windows Vista
>provide a manifest file with your installer (or a separate helper EXE) where you mention level="asInvoker"
Please read
>provide a manifest file with your installer (or a separate helper EXE) where you mention level="requireAdministrator"
Sorry.
# re: Folder Virtualization in Windows Vista
I have developed a windows application using C# on XP system and created an Installer.
If i install this application on XP systems everything was working file.
If i try to install this on Vista Business Edition, getting the permissions problem.
Probelm Description:
while installing the applicatoin on Vista i am creating a shared folder under My Documents. My Application has one feature called "File Uplaod". Once i click on "File Upload", if will save the file in Database and move the file into Shared Folder.
Here the problem occurs. The file is saving to database scuuessfully but it is not moving into Shared Folder. I was getting " Access to the path '\\systemname\Shared Folder\filename' is denied".
Could u plz give me the solution for this sharing problem.
Note:
1. I have given full permissions to the Shared folders
2. If i try to install the same in Vista Ultimate Edition it was working with out any problems.
Regards,
Kishore.
# re: Folder Virtualization in Windows Vista
I'hv a BHO build in VC6(ATL/COM) which is used to create a toolbar button and on button click i called URLDownloadtofile for my specified folder in which the file should be downloaded it works fine on XP but with Vista api URLDownloadtofile not working.
I have set the Protectedmode off option and also login as administrator but still not working.
regards
Himi
# re: Folder Virtualization in Windows Vista
Thanks for the info.
# re: Folder Virtualization in Windows Vista
You can try using a tool like LongPathTool. It helps manage and delete files or folders with long path issues easily.
# re: Folder Virtualization in Windows Vista