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

前端 未结 4 2104
孤独总比滥情好
孤独总比滥情好 2020-12-13 06:38

What is the meaning of these Windows Environment variables:

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

Who

相关标签:
4条回答
  • 2020-12-13 07:12

    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.

    0 讨论(0)
  • 2020-12-13 07:16

    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

    0 讨论(0)
  • 2020-12-13 07:25

    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:

    • [dead link] Environment Variables in Windows NT

    • Where Should I Store my Data and Configuration Files if I Target Multiple OS Versions?

    0 讨论(0)
  • 2020-12-13 07:26

    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.

    0 讨论(0)
提交回复
热议问题