{"id":109137,"date":"2023-12-12T07:00:00","date_gmt":"2023-12-12T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=109137"},"modified":"2023-12-12T07:33:47","modified_gmt":"2023-12-12T15:33:47","slug":"20231212-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20231212-00\/?p=109137","title":{"rendered":"What happens if I define one environment variable in terms of the value of another environment variable?"},"content":{"rendered":"<p>In Windows, you can call up the Environment Variables dialog box to edit both the System environment variables and the User environment variables. What happens if you use the <code>%<\/code> sign to reference one environment variable from another?<\/p>\n<p>Environment variable processing occurs in several steps.\u00b9<\/p>\n<ul>\n<li>Core system environment variables: <code>ALLUSERSPROFILE<\/code>, <code>ProgramData<\/code>, <code>PUBLIC<\/code>, <code>SystemDrive<\/code>, <code>SystemRoot<\/code>.<\/li>\n<li>System environment variables of type <code>REG_SZ<\/code>.<\/li>\n<li>System environment variables of type <code>REG_EXPAND_SZ<\/code>.<\/li>\n<li>Core user environment variables: <code>APPDATA<\/code>, <code>COMPUTERNAME<\/code>, <code>LOCALAPPDATA<\/code>, <code>ProgramFiles<\/code>, <code>USERPROFILE<\/code>.<\/li>\n<li>User environment variables of type <code>REG_SZ<\/code>.<\/li>\n<li>User environment variables of type <code>REG_EXPAND_SZ<\/code>.<\/li>\n<li>Account environment variables: <code>USERDNSDOMAIN<\/code>, <code>USERDOMAIN<\/code>, <code>USERNAME<\/code>.<\/li>\n<\/ul>\n<p>The rule is that each step can redefine variables set by a previous step, and variables of type <code>REG_<wbr \/>EXPAND_<wbr \/>SZ<\/code> can depend on variables set by a previous step, but cannot depend on variables set elsewhere within the same step or by a future step.<\/p>\n<p>This means, for example, that you can use <code>%USERPROFILE%<\/code> in the definition of a User environment variable of type <code>REG_<wbr \/>EXPAND_<wbr \/>SZ<\/code>,, but not in the definition of a System environment variable.<\/p>\n<p>There is a bonus special rule for the <code>PATH<\/code> environment variable: The User definition of the <code>PATH<\/code> environment variable is <i>appended to<\/i> the System definition, rather than replacing it.\u00b2<\/p>\n<p>If you have a <code>REG_<wbr \/>EXPAND_<wbr \/>SZ<\/code> between variables at the same step, it is unspecified whether the expansion is the old value or the new value, so don&#8217;t do that.\u00b3<\/p>\n<p>\u00b9 This is a simplified discussion for the purpose of exposition.<\/p>\n<p>\u00b2 This special rule also applies to the vestigial <code>LibPath<\/code> and <code>Os2LibPath<\/code> environment variables.<\/p>\n<p>\u00b3 To avoid people taking dependencies on implementation details, I would have enforced the rule more strictly and consistently and said that all <code>REG_<wbr \/>EXPAND_<wbr \/>SZ<\/code> expansions use the value of the variable as defined by previous steps, and any changes made in the same step are not visible. But of course the implementation was written before the realization that people would try to create dependencies among variables in the same group.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Only certain types of dependencies are supported.<\/p>\n","protected":false},"author":1069,"featured_media":100998,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[104],"class_list":["post-109137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>Only certain types of dependencies are supported.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=109137"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/109137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/100998"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=109137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=109137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=109137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}