Wednesday, July 11, 2012

Friday, July 6, 2012

RC file for your Windows Command Prompt

I had trouble today with my Windows %HOME% changing and throwing off Vagrant's awareness of what boxes are installed (%HOME%/.vagrant.d/boxes). If Vagrant on Windows was working happily for you and then barfs about no boxes installed, see if this may be your problem.

%HOME% was different depending on whether I logged into Windows while on my Active Directory managed network or while I was offline. When on the AD network, %HOME% is set by policy to a mapped drive. When offline, %HOME% is my Windows %USERPROFILE%. I installed Vagrant and some base boxes while off my AD network and everything worked as expected. Base boxes were added to %USERPROFILE%/.vagrant.d/. Back in the office and logged in on the AD network, Vagrant was no longer aware of the base boxes because %HOME% now pointed at my personal mapped drive.

Creating a batch file to set %HOME% to %USERPROFILE% solved the problem.

REM %USERPROFILE%/cmdrc.bat
@echo off

set HOME=%USERPROFILE%

For UNIXy goodness, name it cmdrc.bat, place it in %USERPROFILE% and then add the following to the registry so that this cmdrc.bat file is run whenever a command prompt opens.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\cmdrc.bat"

--
Figured this out with help from the MinGW wiki's HOWTO Set the HOME variable for cmd exe.