Runtime Revolution
Articles Other News

Revolution and Vista: File and Registry Virtualization

by Marcus van Houdt and Ken Ray


This article discusses file and registry virtualization in Vista and how this may affect Revolution developers.

One of the design goals of Windows Vista was security, and for this reason an array of new technologies is built into the operating system. Virtualization is one of these technologies, and we consider here file and registry virtualization.

File Virtualization

File virtualization is a technology that is intended to provide application compatibility accross Windows Vista. In Windows Vista even administrator accounts do not have default write access to certain system-wide areas such as Program Files. This means that most programs will not have access to Program Files even though some require it to function. For this Vista provides file virtualization, which is a completely opaque method of allowing a write to Program Files but instead of writing to the actual Program Files it writes to a Virtual Store, which is nothing more than a different (user-based) location in the file system.

To see this in action, we can try the following code in Revolution:

local tFile

put merge("[[specialFolderPath(0x0026)]]/test.txt") into tFile

open file tFile for text write

write "foobar" to file tFile

close file tFile

On this particular Vista machine, the specialFolderPath returns "C:/Program Files" for the 0x0026 argument, so we expect a file "test.txt" to be located there. However, this is not the case. Revolution does not have default write permission to Program Files, and thus Vista has (invisibly) redirected the file operations to the virtual store. The test.txt file can actually be found in C:\Users\<username (SID)>\AppData\Local\VirtualStore (notice that AppData is a hidden folder).

(Click to Enlarge Image)

If we run Revolution instead as adminstrator (for example by right-clicking on the executable, and selecting "Run as administrator") then the file will end up in the real Program Files.

(Click to Enlarge Image)

Some pitfalls one should be aware of:

  1. Microsoft intends to do away with virtualization in future versions of the Windows operation system, and it recommends programs store data in a per-user basis instead of relying on virtualization.
  2. If a programs priviliges change (or User Access Controls are disabled by the user), it may lose track of certain files it depends on. If a program's write to Program Files was at one point virtualized, its files would have been written to the virtual store. However, if its permissions change, and it can now write to Program Files, it will no longer have access to the virtual store, but instead has direct access to Program Files.
  3. If the user account is of limited nature, Explorer will provide a virtualized view of Program Files (so the address C:\Program Files may show, but you are not seeing the real Program Files).
  4. There is no way of telling (using Revolution) that a file is located in a virtual store or not. For example, if a Revolution program loads a stack from the virtual Program Files, put the filename of this stack will return "C:/Program Files/mystack.rev". In most cases this should not be a problem, but is best to avoid problems by writing to per-user locations.
  5. specialFolderPath(0x0026) (and others) will not return paths to virtual stores, as these are handled by Vista at a lower level instead of by Revolution itself.

Registry Virtulization

Analogous to file virtualization, Vista also provides registry virtualization. When writing to the Registry, to HKEY_LOCAL_MACHINE\SOFTWARE, any writes that are not allowed due to inadequate permissions are redirected to HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE.

To illustrate this let's try and set a registry key in Revolution (again, we are using an adiminstrator account, but Revolution runs with default permissions).

get setRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\RevTest\testkey", "foobar");

We can use "regedit" to inspect the registry. Indeed, we can find no such value HKEY_LOCAL_MACHINE\SOFTWARE\RevTest\testkey in the registry. Instead, we can find the registry key virtualized:

(Click to Enlarge Image)

As they say, knowledge is power. If you bear these things in mind when writing your software for Vista, you should avoid the pitfalls and enjoy smooth application creation with added security, using Revolution 2.8 to create Vista compatible programs.

Our thanks to Ken Ray for drawing these issues to our attention. You can see more of his excellent Revolution tips, tricks and tutorials online.

©2005 Runtime Revolution Ltd, 15-19 York Place, Edinburgh, Scotland, UK, EH1 3EB.
Questions? Email for answers.