What is the meaning of these Windows Environment variables: HOMEDRIVE, HOMEPATH, HOMESHARE, USERPROFILE

Andrea Francia picture Andrea Francia · Mar 3, 2009 · Viewed 39.3k times · Source

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?

Answer

ivan_pozdeev picture ivan_pozdeev · Apr 4, 2016

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 an older code that persists since NT4 days. Difference between profile and home path - Server Fault confirms that.