Dynamic user home directory on Windows (changing %HOMEDRIVE% and %HOMEPATH%)

admin

Administrator
Staff member
<h2>Actual question</h2>

How can I "redirect" (symbolic links?) or temporarily change the values of
Code:
%HOMEDRIVE%
and
Code:
%HOMEPATH%
(maybe based on two batch scripts that change the values when I start working at the machine and reset everything after I'm done)?

<h2>Background</h2>

A lot of Windows programs pick up either system variable
Code:
%USERPROFILE%
or a combination of
Code:
%HOMEDRIVE%
and
Code:
%HOMEPATH
in order to figure out where a user's "home" directory is that they need to use (e.g.
Code:
C:\Users\JohnDoe
). Being a fan of the philosophy of <em>portable apps</em> (see at the bottom what I mean by that), I'm wondering if I could somehow make my home directory portable, i.e. have it point to a directory on a portable device. Or, in other words, I would like to make it "dynamically changeable".

<h2>What I tried</h2>

I've read a bit about <a href="http://ss64.com/nt/set.html" rel="nofollow">
Code:
Set
</a> and <a href="http://technet.microsoft.com/en-us/library/cc755104.aspx" rel="nofollow">
Code:
Setx
</a> and tried this:

Finding out what the current variable values are:

Code:
C:\Users\JohnDoe&gt; Set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\&lt;username&gt;

Set them:

Code:
C:\Users\JohnDoe&gt; Setx HOMEDRIVE "d:"
C:\Users\JohnDoe&gt; Setx HOMEPATH "\home"

That creates
Code:
HOMEDIR
and
Code:
HOMEPATH
as user-specific environment variables (see Control Panel >> System >> Environment Variables). But the "global ones" did not change and e.g. RStudio will not recognize the user-specific variables (still writes to
Code:
C:\Users\JohnDoes\[...]
).

Code:
C:\Users\JohnDoe&gt; Set HOME
HOMEDRIVE=C:
HOMEPATH=\Users\&lt;username&gt;

<hr>

<h2>Portable Apps</h2>

For example, see PortableApps.com or simply think "software that simply has been installed to a portable device instead of
Code:
C:\Program Files\&lt;app-name&gt;
". The latter works a treat for me for programs that don't really care about
Code:
%HOMEDRIVE%
and
Code:
%HOMEPATH%
(e.g. <a href="https://www.eclipse.org/" rel="nofollow">Eclipse</a> or <a href="http://www.r-project.org/" rel="nofollow">R</a>).

Some others (e.g. <a href="http://git-scm.com/" rel="nofollow">Git</a>) just need to be tweaked a little bit (e.g. see <a href="http://danlimerick.wordpress.com/20...s-tip-setting-home-and-the-startup-directory/" rel="nofollow">this post</a>).

Yet some others (e.g. <a href="http://www.rstudio.com/" rel="nofollow">RStudio</a>) run in fact smoothly off the portable device, but write stuff to the user's "home" directory. That's the kind of software that I would like to tell to use a directory on my portable device instead.