Moving User and Program Files folders under Windows 7

Note: It is important to format all drive partitions you intend on using before attempting to move the user and program file directories. Without properly formatted drives, the partitions will not register with the Windows 7 Setup program properly and chaos will ensue. Or, more accurately, you will be unable to properly move the directories.

During the install of Windows 7, when you are shown the “User Creation” prompt, press Shift+F10. This will give you access to a DOS prompt.

Once here, perform the following commands:

diskpart

This will bring you into the Microsoft DiskPart program. It can perform partitioning and formatting actions on a machine, but we’re just here for two commands:

list volume
exit

This should list all mounted drives on the machine and their corresponding drive letter. Determine which drive has the system files on it currently and which drive(s) you want to copy the data to.

robocopy C:\users <drive>:\users /E /COPYALL /XJ
robocopy "C:\Program Files" "<drive>:\Program Files" /E /COPYALL /XJ
robocopy C:\programdata <drive>:\programdata /E /COPYALL /XJ

and, if you are on a 64-bit system:

robocopy “C:\program files (x86)” “<drive>:\program files (x86)” /E /COPYALL /XJ

We then need to remove the old directories and create junction points to the new ones:

rmdir C:\Users /S /Q
rmdir "C:\Program Files" /S /Q
rmdir C:\Programdata /S /Q

and, if you’re on a 64-bit system:

rmdir "C:\Program Files (x86)" /S /Q

(Note, it is possible the ProgramData directory won’t delete properly. This can be rectified by logging in to the “Repair Your Computer” startup option after finishing the initial load and removing as per the instructions above.)

After removing the old directories we must create “fake” directories pointing to the new actual locations of the directories. This is accomplished through the use of junction links.

(It is important to note that, in many cases, the drive letters shown during the Windows install process – and when using the “Repair Your Computer” function – will show differently than the drive letters in Windows. As long as the physical drives where you are creating the junction links’ source and destination are correct, the links will work properly in Windows.)

Create the three (or four) links you’ll need to move your folders:

mklink /J "C:\Program Files" "<drive>:\Program Files"
mklink /J C:\users <drive>:\users
mklink /J C:\programdata <drive>:\programdata

And if you’re on a 64-bit system:

mklink /J "C:\Program Files (x86)" "<drive>:\Program Files (x86)"

Now, we need to correct registry entries pertaining to these items:

  • Navigate to HKLM\Software\Microsoft \Windows\CurrentVersion
    • Change the “CommonFilesDir” and “ProgramFilesDir” variables to indicate the new directory, as well as any other variables containing links to the old (source) drive.
  • Navigate to HKLM\Software\Microsoft \Windows NT\CurrentVersion\ProfileList
    • Change the “Default” and “Public” variables to indicate the new directory, as well as any other variables containing links to the old (source) drive.

And if you’re on a 64-bit system:

  • Navigate to HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion and HKLM\SOFTWARE\Wow6432Node\Microsoft\WindowsNT \CurrentVersion\ProfileSet and change any incorrect values there as well.

After all this, the folders should be properly moved (unless the ProgramData folder did not completely move, and that can be rectified after a reboot as noted above) and everything should be copacetic.