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

4

50

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?

Tourneur answered 3/3, 2009 at 14:1 Comment(0)
G
41

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.

Glabrous answered 3/4, 2016 at 23:35 Comment(2)
very interesting that HOMEDRIVE and HOMEPATH don't exist if the user has never logged in (read: ran explorer.exe)Topflight
Thanks for this answer, they helps me to understand a problem that happend for me in git-bash for windows (See this github.com/git-for-windows/git/issues/2709)Effendi
S
24

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:

Stockpile answered 10/1, 2012 at 2:30 Comment(5)
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?Isborne
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.Stockpile
@CarlBosch E.g. net user <username> /HOMEDIR:<path> can set it (there since at least win2k).Glabrous
Note that %HOMEPATH% should always be preprended with %HOMEDRIVE%Mandi
%HOMEDRIVE% and %HOMEPATH% can be set by the organization via Active Directory (source). In my case they were set to a network drive location.Sod
V
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

Villain answered 3/3, 2009 at 14:5 Comment(1)
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)Elenoraelenore
M
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.

Maseru answered 15/4, 2009 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.