这些 Windows 环境变量的含义是什么:HOMEDRIVE、HOMEPATH、HOMESHARE、USERPROFILE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/606483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of these Windows Environment variables: HOMEDRIVE, HOMEPATH, HOMESHARE, USERPROFILE
提问by Andrea Francia
What is the meaning of these Windows Environment variables:
这些 Windows 环境变量的含义是什么:
- 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?
samba服务器的配置如何修改这些变量?
回答by Peter Tseng
HOMEDRIVE
/HOMEPATH
is where the user's personal files are: downloads, music, documents, etc.
HOMEDRIVE
/HOMEPATH
是用户个人文件所在的位置:下载、音乐、文档等。
HOMESHARE
is used instead of HOMEDRIVE
if the home directory uses UNC paths.
HOMESHARE
HOMEDRIVE
如果主目录使用 UNC 路径,则使用。
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.
USERPROFILE
用于存储用户的应用程序和操作系统配置文件以及个性化设置。它包括本地和漫游(Active Directory)文件夹。似乎人们比HOMEPATH
现在更喜欢使用它。
It's important to note that although HOMEDRIVE
/HOMEPATH
is often the same path as USERPROFILE
, it's not always the case.
需要注意的是,虽然HOMEDRIVE
/HOMEPATH
通常与 路径相同USERPROFILE
,但情况并非总是如此。
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.
我认为 Samba 不会修改这些。它可能会利用它们来提供初始(主)目录。但是,Active Directory 可能会更改它们。
References:
参考:
回答by ivan_pozdeev
USERPROFILE
is set by userenv!LoadUserProfileW
which is called when, well, loading the user's profile (the HKEY_USERS\<sid>
hive).
USERPROFILE
由userenv!LoadUserProfileW
which设置,在加载用户的配置文件(HKEY_USERS\<sid>
配置单元)时调用。
- 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
forrunas
) then the process is run in theDefault User
profile which still has this variable set - since the moment itwas loaded at system's startup.
- 这通常发生在第一次为用户启动进程时。
- 如果您特别安排不加载配置文件(例如使用
/noprofile
forrunas
),那么进程将在Default User
仍然设置了此变量的配置文件中运行- 从它在系统启动时加载的那一刻起。
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.
HOMEDRIVE
,HOMEPATH
和HOMESHARE
(以及其他几个变量)由shell32!RegenerateUserEnvironment
which 在 Explorer 初始化1 时调用。它们被放置在(易失性)HKCU\Volatile Environment
键中,该键是易失性的,在配置文件卸载之前一直存在。
- 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.
- No wonder people prefer
- 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'schmod
).
- 因此,它们仅在用户登录其桌面会话时设置。不适用于辅助登录或服务。
- 对于
HOMEPATH
要设置,SYSTEM
必须为配置文件的目录权限(它们是最初设置的,当然,但是当如摆弄Cygwin的可能消失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 Faultconfirms that.
1代码还设置了一些已由 设置的变量userenv
。这表明这是一个较旧的代码,自 NT4 天以来一直存在。配置文件和主路径之间的区别 - Server Fault证实了这一点。
回答by lfaraone
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.
这些都是在登录时设置的,正如 SocialAddict 所说,当您需要在不同系统上执行操作时,它们在脚本中非常有用。
I'm not too clear on your other question, a samba server shouldn't care about those variables.
我对你的另一个问题不太清楚,samba 服务器不应该关心这些变量。
See http://vlaurie.com/computers2/Articles/environment.htmfor a detailed explanation.
有关详细说明,请参阅http://vlaurie.com/computers2/Articles/environment.htm。
回答by Andrew
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.
然后它将转到您机器上设置的环境路径。例如,在编写 vb 脚本以及您想要在用户配置文件区域执行任务的地方时,它很有用。
Hope this helps
希望这可以帮助