48

What is the meaning of these Windows Environment variables:

  • HOMEDRIVE,
  • HOMEPATH,
  • HOMESHARE,
  • and USERPROFILE?

Who set them? When? Who use them? For doing what?

How the configuration of the samba server modify these variables?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Andrea Francia
  • 9,737
  • 16
  • 56
  • 70

4 Answers4

38

USERPROFILE is set by userenv!LoadUserProfileW which is called when, well, loading the user's profile (the HKEY_USERS\<sid> hive).

  • This typically happens the first time a process is started for the user.
  • If you specifically arranged not to load the profile (e.g. with /noprofile for runas) then the process is run in the Default User profile which still has this variable set - since the moment it was loaded at system's startup.

HOMEDRIVE, HOMEPATH and HOMESHARE (as well as several other variables) are set by shell32!RegenerateUserEnvironment which is called on Explorer initialization1. They are placed in the (volatile) HKCU\Volatile Environment key which, being volatile, persists until the profile's unload.

1The code also sets a few variables that are already set by userenv. This suggests that this is older code that persists since NT4 days. Difference between profile and home path - Server Fault confirms that.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
  • very interesting that HOMEDRIVE and HOMEPATH don't exist if the user has never logged in (read: ran explorer.exe) – Floris Devreese Oct 11 '19 at 13:04
  • 1
    Thanks for this answer, they helps me to understand a problem that happend for me in git-bash for windows (See this https://github.com/git-for-windows/git/issues/2709) – Radon8472 Jun 26 '20 at 22:03
23

HOMEDRIVE/HOMEPATH is where the user's personal files are: downloads, music, documents, etc.

HOMESHARE is used instead of HOMEDRIVE if the home directory uses UNC paths.

USERPROFILE is used to store the user's application and OS configuration files and personalization settings. It includes both local and roaming (Active Directory) folders. It seems like people favor using this more than HOMEPATH nowadays.

It's important to note that although HOMEDRIVE/HOMEPATH is often the same path as USERPROFILE, it's not always the case.

I don't think Samba would modify these. It might make use of them to provide an initial (home) directory. Active Directory may change them though.


References:

Ky -
  • 30,724
  • 51
  • 192
  • 308
Peter Tseng
  • 13,613
  • 4
  • 67
  • 57
  • 3
    Quote: "It's important to note that although HOMEDRIVE/HOMEPATH is often the same path as USERPROFILE, it's not always the case." Do you happen to know when it is different? – Carl Bosch Apr 28 '15 at 09:21
  • 1
    I believe the HOMEDRIVE/HOMEPATH directory can be modified fairly easily - e.g. to use a network share or different hard drive - in which case it would become different from USERPROFILE. – Peter Tseng Apr 28 '15 at 19:59
  • 1
    @CarlBosch E.g. [`net user /HOMEDIR:`](https://support.microsoft.com/en-us/kb/320043) can set it (there since at least win2k). – ivan_pozdeev Apr 03 '16 at 22:33
  • 1
    Note that %HOMEPATH% should always be preprended with %HOMEDRIVE% – Raúl Salinas-Monteagudo Apr 10 '19 at 06:32
  • %HOMEDRIVE% and %HOMEPATH% can be set by the organization via Active Directory ([source](https://social.technet.microsoft.com/Forums/windows/en-US/e9d9cd4d-6882-459e-b7a8-7091cfa031d2/where-are-user-environment-variables-homedrive-homepath-set?forum=winserverTS)). In my case they were set to a network drive location. – chinookf Oct 14 '20 at 20:47
3

if you go to the run box and type any of the above like this

%HOMEPATH%

then it will go to your environment path that is set on your machine. It's usefull when writing vb scrips and things like that where you want to perform a task on the users profile area for example.

Hope this helps

Andrew
  • 9,967
  • 10
  • 64
  • 103
  • 2
    This doesn't really work depending on the config and current drive of the Explorer process... On my machine, %HOMEPATH% is `\ ` (%HOMEDRIVE% is `Z:`) and if I put %HOMEPATH% in the Run window, it opens `C:\ `... (now, I can't guarantee it would always open that specific drive) – Ale Apr 17 '20 at 12:39
1

Those are all set on login, and they are, as SocialAddict said, very useful in scripts when you need to perform an action on different systems.

I'm not too clear on your other question, a samba server shouldn't care about those variables.

See http://vlaurie.com/computers2/Articles/environment.htm for a detailed explanation.

lfaraone
  • 49,562
  • 17
  • 52
  • 70