Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

windows

samba

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?

like image 236
Andrea Francia Avatar asked Mar 03 '09 14:03

Andrea Francia


1 Answers

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.

  • Consequently, they are only set when the user logins into their desktop session. NOT for secondary logons or services.
    • No wonder people prefer USERPROFILE nowadays.
  • For HOMEPATH to be set, SYSTEM must have permissions for the profile's directory (they are initially set, of course, but may vanish when e.g. playing with Cygwin's chmod).

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.

like image 139
ivan_pozdeev Avatar answered Oct 11 '22 14:10

ivan_pozdeev