Using Cygwin on Windows Vista as an Administrator
I’ve just managed to fix a particularly annoying issue I was having with Cygwin under Vista with UAC enabled. Essentially, when I ran the Cygwin bash shell as an Administrator I was seeing the following:
- Bash started in
/bin/
- The bash shell had no knowledge of Unix paths (i.e. the current working directory was
/c/Cygwin/bin
) - The root file system was just my C: drive
- My
.bashrc
and.bash_profile
were not being executed
All of this made it fairly hard to actually do anything. However, I was given a clue when I started up Poderosa (a nice GUI terminal emulator) and tried to open a Cygwin console: there was an error message about not being able to access HKEY_CURRENT_USER\Software\Cygnus Solutions\Cygwin\mounts v2\/. This key contains the mount information for the root directory of the Cygwin instance, so it looked like the root of the problem.
I then opened up Process Monitor to see what happened when, running under the Administrator user, Poderosa tried to access that key. It got “NAME NOT FOUND” as expected. I then tried the same thing as a normal user, and found that the response code was “REPARSE” instead! The log looked like this:
What, do you ask, is all that VirtualStore nonsense after the REPARSE has occurred? Well, that REPARSE is actually redirecting Poderosas read of the LOCAL_MACHINE registry key to some keys in the CURRENT_USER hive: this is a new “feature” of Windows Vista designed to ensure that old applications that assume they can write to LOCAL_MACHINE still work. Any such writes by a process without the appropriate permissions are redirected to the VirtualStore instead, and then read back later transparently by this REPARSE mechanism. However, in their wisdom Microsoft have decided that this redirection is disabled when applications are run as an Administrator from a UAC protected account.
What must have happened is that I accidentally installed or modified Cygwin using the Setup program as a normal user, and it’s writes to HKLM were hence redirected to VirtualStore, which is then not consulted when you try and run Cygwin proper as an Administrator. My fix was simply to:
- Export the VirtualStore branch as a “.reg” file from the registry editor
- Open the resulting file in Notepad and replace the text “HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE” with “HKEY_LOCAL_MACHINE”
- Import the modified .reg file using the registry editor again
After that process the user-private data written by Cygwin setup was accessible machine-wide, solving my problem. I hope that this post will be able to help out someone else with similar problems!