Where do the environment variables for an elevated cmd.exe process come from?












1














The environment variables shown by the SET command can be notably different depending on the
privilege level of the command prompt session. Moreover, it seems that any program run with
administrative credentials by the same user can create environment variables that will persist long after that process ends, and will be set in any subsequent elevated process
launched by that user (and ONLY in those elevated processes). I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated
with the user login session. My Question is: where are those values stored, and why is
Process Explorer unable to access them (of course, since Process Explorer runs elevated by
default those variables appear in its own Environment tab)? Or did I just overlook them?










share|improve this question



























    1














    The environment variables shown by the SET command can be notably different depending on the
    privilege level of the command prompt session. Moreover, it seems that any program run with
    administrative credentials by the same user can create environment variables that will persist long after that process ends, and will be set in any subsequent elevated process
    launched by that user (and ONLY in those elevated processes). I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated
    with the user login session. My Question is: where are those values stored, and why is
    Process Explorer unable to access them (of course, since Process Explorer runs elevated by
    default those variables appear in its own Environment tab)? Or did I just overlook them?










    share|improve this question

























      1












      1








      1


      1





      The environment variables shown by the SET command can be notably different depending on the
      privilege level of the command prompt session. Moreover, it seems that any program run with
      administrative credentials by the same user can create environment variables that will persist long after that process ends, and will be set in any subsequent elevated process
      launched by that user (and ONLY in those elevated processes). I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated
      with the user login session. My Question is: where are those values stored, and why is
      Process Explorer unable to access them (of course, since Process Explorer runs elevated by
      default those variables appear in its own Environment tab)? Or did I just overlook them?










      share|improve this question













      The environment variables shown by the SET command can be notably different depending on the
      privilege level of the command prompt session. Moreover, it seems that any program run with
      administrative credentials by the same user can create environment variables that will persist long after that process ends, and will be set in any subsequent elevated process
      launched by that user (and ONLY in those elevated processes). I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated
      with the user login session. My Question is: where are those values stored, and why is
      Process Explorer unable to access them (of course, since Process Explorer runs elevated by
      default those variables appear in its own Environment tab)? Or did I just overlook them?







      windows environment-variables






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 20 '12 at 6:34









      kreemoweet

      3,5621214




      3,5621214






















          3 Answers
          3






          active

          oldest

          votes


















          1















          Where do the environment variables for an elevated cmd.exe process come from?




          Like all processes, it gets its environment from the process that spawned the command-prompt instance.



          When a process spawns another process, the child process inherits the parent’s environment. If the parent was privileged, then it probably has more/different variables than if it isn’t. When it spawns a child process, the child gets the same set to start with.




          The environment variables shown by the SET command can be notably different depending on the privilege level of the command prompt session.




          Because when Explorer doesn’t actually spawn privileged processes, the CSRSS does. When you run a program “as admin”, you get a UAC prompt which dims the screen. This is because the CSRSS is a system process which handles UAC prompts and process-elevation. So while Explorer and its child processes have one environment, an elevated command-prompt (which is spawned by the high-privilege system process at the behest of Explorer) gets a slightly different set with some extra/different variables.




          Moreover, it seems that any program run with administrative credentials by the same user can create environment variables that will persist long after that process ends and will be set in any subsequent elevated process launched by that user (and ONLY in those elevated processes).




          Nope. The set command is session-only. Once you close that command-prompt, any changes you’ve made go poof. To make persistent changes, you must use an external tool like a third-party utility or the Microsoft tool program setx. This is true of even elevated command-prompts; the set command simply has no functionality to modify the environment in the registry.




          I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated with the user login session.




          Because any changes you make with set will only be visible in that specific command-prompt and any processes that you launch from That specific command-prompt; the changes do not propagate to other processes.




          My Question is where are those values stored, and why is Process Explorer unable to access them (of course, since Process Explorer runs elevated by default those variables appear in its own Environment tab)? Or did I just overlook them?




          The session variables are stored in that specific command-prompt’s environment. Process Explorer can see them for that specific instance of cmd, but they won’t be in any other process. If you launch a program from that command-prompt, then you can see those changes in the child process’ Environment tab in Process Explorer because it will have inherited them from that command-prompt.



          If you use a program like setx to set a persistent variable, then they will be stored in the registry. If you set a user-level variable (for the current user), it will be stored in HKCUEnvironment (or HKU<USER>Environment for other users). If you set a system-level variable, then it will be stored in HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment.



          Be aware that if you manually modify the environment through the registry, only new processes will pick up the changes. To get existing process to see the changes, you have to either restart them or broadcast a WM_SETTINGCHANGE message. (Tools like setx broadcast the message to all top-level windows.)






          share|improve this answer





























            0














            I think the output of SET can only be different when you're not logged in as a member of the Administrator group. That's why you're asked for a user/password in that case, you actually login as a Administrator for that process.



            If you are already a member of the administrator group, then the output of SET is the same in both cases for me.



            Therefore, if my hypothesis is true, the elevated privilege variables are defined as User Variables for Administrator.






            share|improve this answer





























              0














              It is not very clear exactly how the environment variables are set in a newly created elevated process, but most of them come from the current user's existing set (as shown by the non-elevated cmd.exe SET command), as well as any that exist in the user's HKCU/Volatile Environment registry key, which have been created since the start of the current login session (or current instance of Explorer?) and are not shown in the non-elevated SET list. There are a few variables in my Windows 10 which occur in the non-elevated list but not the elevated one.



              This question was motivated by the behavior of older versions of Macrium Reflect, which is discussed at https://forum.macrium.com/Topic752-1.aspx The current version of that program now creates those problematic variables at HKU/.DEFAULT/Volatile Environment (AKA HKU/S-1-5-18/Volatile Environment) instead of under the HKCU key.






              share|improve this answer























                Your Answer








                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "3"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f477344%2fwhere-do-the-environment-variables-for-an-elevated-cmd-exe-process-come-from%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1















                Where do the environment variables for an elevated cmd.exe process come from?




                Like all processes, it gets its environment from the process that spawned the command-prompt instance.



                When a process spawns another process, the child process inherits the parent’s environment. If the parent was privileged, then it probably has more/different variables than if it isn’t. When it spawns a child process, the child gets the same set to start with.




                The environment variables shown by the SET command can be notably different depending on the privilege level of the command prompt session.




                Because when Explorer doesn’t actually spawn privileged processes, the CSRSS does. When you run a program “as admin”, you get a UAC prompt which dims the screen. This is because the CSRSS is a system process which handles UAC prompts and process-elevation. So while Explorer and its child processes have one environment, an elevated command-prompt (which is spawned by the high-privilege system process at the behest of Explorer) gets a slightly different set with some extra/different variables.




                Moreover, it seems that any program run with administrative credentials by the same user can create environment variables that will persist long after that process ends and will be set in any subsequent elevated process launched by that user (and ONLY in those elevated processes).




                Nope. The set command is session-only. Once you close that command-prompt, any changes you’ve made go poof. To make persistent changes, you must use an external tool like a third-party utility or the Microsoft tool program setx. This is true of even elevated command-prompts; the set command simply has no functionality to modify the environment in the registry.




                I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated with the user login session.




                Because any changes you make with set will only be visible in that specific command-prompt and any processes that you launch from That specific command-prompt; the changes do not propagate to other processes.




                My Question is where are those values stored, and why is Process Explorer unable to access them (of course, since Process Explorer runs elevated by default those variables appear in its own Environment tab)? Or did I just overlook them?




                The session variables are stored in that specific command-prompt’s environment. Process Explorer can see them for that specific instance of cmd, but they won’t be in any other process. If you launch a program from that command-prompt, then you can see those changes in the child process’ Environment tab in Process Explorer because it will have inherited them from that command-prompt.



                If you use a program like setx to set a persistent variable, then they will be stored in the registry. If you set a user-level variable (for the current user), it will be stored in HKCUEnvironment (or HKU<USER>Environment for other users). If you set a system-level variable, then it will be stored in HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment.



                Be aware that if you manually modify the environment through the registry, only new processes will pick up the changes. To get existing process to see the changes, you have to either restart them or broadcast a WM_SETTINGCHANGE message. (Tools like setx broadcast the message to all top-level windows.)






                share|improve this answer


























                  1















                  Where do the environment variables for an elevated cmd.exe process come from?




                  Like all processes, it gets its environment from the process that spawned the command-prompt instance.



                  When a process spawns another process, the child process inherits the parent’s environment. If the parent was privileged, then it probably has more/different variables than if it isn’t. When it spawns a child process, the child gets the same set to start with.




                  The environment variables shown by the SET command can be notably different depending on the privilege level of the command prompt session.




                  Because when Explorer doesn’t actually spawn privileged processes, the CSRSS does. When you run a program “as admin”, you get a UAC prompt which dims the screen. This is because the CSRSS is a system process which handles UAC prompts and process-elevation. So while Explorer and its child processes have one environment, an elevated command-prompt (which is spawned by the high-privilege system process at the behest of Explorer) gets a slightly different set with some extra/different variables.




                  Moreover, it seems that any program run with administrative credentials by the same user can create environment variables that will persist long after that process ends and will be set in any subsequent elevated process launched by that user (and ONLY in those elevated processes).




                  Nope. The set command is session-only. Once you close that command-prompt, any changes you’ve made go poof. To make persistent changes, you must use an external tool like a third-party utility or the Microsoft tool program setx. This is true of even elevated command-prompts; the set command simply has no functionality to modify the environment in the registry.




                  I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated with the user login session.




                  Because any changes you make with set will only be visible in that specific command-prompt and any processes that you launch from That specific command-prompt; the changes do not propagate to other processes.




                  My Question is where are those values stored, and why is Process Explorer unable to access them (of course, since Process Explorer runs elevated by default those variables appear in its own Environment tab)? Or did I just overlook them?




                  The session variables are stored in that specific command-prompt’s environment. Process Explorer can see them for that specific instance of cmd, but they won’t be in any other process. If you launch a program from that command-prompt, then you can see those changes in the child process’ Environment tab in Process Explorer because it will have inherited them from that command-prompt.



                  If you use a program like setx to set a persistent variable, then they will be stored in the registry. If you set a user-level variable (for the current user), it will be stored in HKCUEnvironment (or HKU<USER>Environment for other users). If you set a system-level variable, then it will be stored in HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment.



                  Be aware that if you manually modify the environment through the registry, only new processes will pick up the changes. To get existing process to see the changes, you have to either restart them or broadcast a WM_SETTINGCHANGE message. (Tools like setx broadcast the message to all top-level windows.)






                  share|improve this answer
























                    1












                    1








                    1







                    Where do the environment variables for an elevated cmd.exe process come from?




                    Like all processes, it gets its environment from the process that spawned the command-prompt instance.



                    When a process spawns another process, the child process inherits the parent’s environment. If the parent was privileged, then it probably has more/different variables than if it isn’t. When it spawns a child process, the child gets the same set to start with.




                    The environment variables shown by the SET command can be notably different depending on the privilege level of the command prompt session.




                    Because when Explorer doesn’t actually spawn privileged processes, the CSRSS does. When you run a program “as admin”, you get a UAC prompt which dims the screen. This is because the CSRSS is a system process which handles UAC prompts and process-elevation. So while Explorer and its child processes have one environment, an elevated command-prompt (which is spawned by the high-privilege system process at the behest of Explorer) gets a slightly different set with some extra/different variables.




                    Moreover, it seems that any program run with administrative credentials by the same user can create environment variables that will persist long after that process ends and will be set in any subsequent elevated process launched by that user (and ONLY in those elevated processes).




                    Nope. The set command is session-only. Once you close that command-prompt, any changes you’ve made go poof. To make persistent changes, you must use an external tool like a third-party utility or the Microsoft tool program setx. This is true of even elevated command-prompts; the set command simply has no functionality to modify the environment in the registry.




                    I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated with the user login session.




                    Because any changes you make with set will only be visible in that specific command-prompt and any processes that you launch from That specific command-prompt; the changes do not propagate to other processes.




                    My Question is where are those values stored, and why is Process Explorer unable to access them (of course, since Process Explorer runs elevated by default those variables appear in its own Environment tab)? Or did I just overlook them?




                    The session variables are stored in that specific command-prompt’s environment. Process Explorer can see them for that specific instance of cmd, but they won’t be in any other process. If you launch a program from that command-prompt, then you can see those changes in the child process’ Environment tab in Process Explorer because it will have inherited them from that command-prompt.



                    If you use a program like setx to set a persistent variable, then they will be stored in the registry. If you set a user-level variable (for the current user), it will be stored in HKCUEnvironment (or HKU<USER>Environment for other users). If you set a system-level variable, then it will be stored in HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment.



                    Be aware that if you manually modify the environment through the registry, only new processes will pick up the changes. To get existing process to see the changes, you have to either restart them or broadcast a WM_SETTINGCHANGE message. (Tools like setx broadcast the message to all top-level windows.)






                    share|improve this answer













                    Where do the environment variables for an elevated cmd.exe process come from?




                    Like all processes, it gets its environment from the process that spawned the command-prompt instance.



                    When a process spawns another process, the child process inherits the parent’s environment. If the parent was privileged, then it probably has more/different variables than if it isn’t. When it spawns a child process, the child gets the same set to start with.




                    The environment variables shown by the SET command can be notably different depending on the privilege level of the command prompt session.




                    Because when Explorer doesn’t actually spawn privileged processes, the CSRSS does. When you run a program “as admin”, you get a UAC prompt which dims the screen. This is because the CSRSS is a system process which handles UAC prompts and process-elevation. So while Explorer and its child processes have one environment, an elevated command-prompt (which is spawned by the high-privilege system process at the behest of Explorer) gets a slightly different set with some extra/different variables.




                    Moreover, it seems that any program run with administrative credentials by the same user can create environment variables that will persist long after that process ends and will be set in any subsequent elevated process launched by that user (and ONLY in those elevated processes).




                    Nope. The set command is session-only. Once you close that command-prompt, any changes you’ve made go poof. To make persistent changes, you must use an external tool like a third-party utility or the Microsoft tool program setx. This is true of even elevated command-prompts; the set command simply has no functionality to modify the environment in the registry.




                    I have not been able to find those variables in the Environment tab shown by Process Explorer for any process associated with the user login session.




                    Because any changes you make with set will only be visible in that specific command-prompt and any processes that you launch from That specific command-prompt; the changes do not propagate to other processes.




                    My Question is where are those values stored, and why is Process Explorer unable to access them (of course, since Process Explorer runs elevated by default those variables appear in its own Environment tab)? Or did I just overlook them?




                    The session variables are stored in that specific command-prompt’s environment. Process Explorer can see them for that specific instance of cmd, but they won’t be in any other process. If you launch a program from that command-prompt, then you can see those changes in the child process’ Environment tab in Process Explorer because it will have inherited them from that command-prompt.



                    If you use a program like setx to set a persistent variable, then they will be stored in the registry. If you set a user-level variable (for the current user), it will be stored in HKCUEnvironment (or HKU<USER>Environment for other users). If you set a system-level variable, then it will be stored in HKLMSYSTEMCurrentControlSetControlSession ManagerEnvironment.



                    Be aware that if you manually modify the environment through the registry, only new processes will pick up the changes. To get existing process to see the changes, you have to either restart them or broadcast a WM_SETTINGCHANGE message. (Tools like setx broadcast the message to all top-level windows.)







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 8 '13 at 4:28









                    Synetech

                    57k29184317




                    57k29184317

























                        0














                        I think the output of SET can only be different when you're not logged in as a member of the Administrator group. That's why you're asked for a user/password in that case, you actually login as a Administrator for that process.



                        If you are already a member of the administrator group, then the output of SET is the same in both cases for me.



                        Therefore, if my hypothesis is true, the elevated privilege variables are defined as User Variables for Administrator.






                        share|improve this answer


























                          0














                          I think the output of SET can only be different when you're not logged in as a member of the Administrator group. That's why you're asked for a user/password in that case, you actually login as a Administrator for that process.



                          If you are already a member of the administrator group, then the output of SET is the same in both cases for me.



                          Therefore, if my hypothesis is true, the elevated privilege variables are defined as User Variables for Administrator.






                          share|improve this answer
























                            0












                            0








                            0






                            I think the output of SET can only be different when you're not logged in as a member of the Administrator group. That's why you're asked for a user/password in that case, you actually login as a Administrator for that process.



                            If you are already a member of the administrator group, then the output of SET is the same in both cases for me.



                            Therefore, if my hypothesis is true, the elevated privilege variables are defined as User Variables for Administrator.






                            share|improve this answer












                            I think the output of SET can only be different when you're not logged in as a member of the Administrator group. That's why you're asked for a user/password in that case, you actually login as a Administrator for that process.



                            If you are already a member of the administrator group, then the output of SET is the same in both cases for me.



                            Therefore, if my hypothesis is true, the elevated privilege variables are defined as User Variables for Administrator.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 12 '13 at 20:08









                            Juan Mendes

                            1014




                            1014























                                0














                                It is not very clear exactly how the environment variables are set in a newly created elevated process, but most of them come from the current user's existing set (as shown by the non-elevated cmd.exe SET command), as well as any that exist in the user's HKCU/Volatile Environment registry key, which have been created since the start of the current login session (or current instance of Explorer?) and are not shown in the non-elevated SET list. There are a few variables in my Windows 10 which occur in the non-elevated list but not the elevated one.



                                This question was motivated by the behavior of older versions of Macrium Reflect, which is discussed at https://forum.macrium.com/Topic752-1.aspx The current version of that program now creates those problematic variables at HKU/.DEFAULT/Volatile Environment (AKA HKU/S-1-5-18/Volatile Environment) instead of under the HKCU key.






                                share|improve this answer




























                                  0














                                  It is not very clear exactly how the environment variables are set in a newly created elevated process, but most of them come from the current user's existing set (as shown by the non-elevated cmd.exe SET command), as well as any that exist in the user's HKCU/Volatile Environment registry key, which have been created since the start of the current login session (or current instance of Explorer?) and are not shown in the non-elevated SET list. There are a few variables in my Windows 10 which occur in the non-elevated list but not the elevated one.



                                  This question was motivated by the behavior of older versions of Macrium Reflect, which is discussed at https://forum.macrium.com/Topic752-1.aspx The current version of that program now creates those problematic variables at HKU/.DEFAULT/Volatile Environment (AKA HKU/S-1-5-18/Volatile Environment) instead of under the HKCU key.






                                  share|improve this answer


























                                    0












                                    0








                                    0






                                    It is not very clear exactly how the environment variables are set in a newly created elevated process, but most of them come from the current user's existing set (as shown by the non-elevated cmd.exe SET command), as well as any that exist in the user's HKCU/Volatile Environment registry key, which have been created since the start of the current login session (or current instance of Explorer?) and are not shown in the non-elevated SET list. There are a few variables in my Windows 10 which occur in the non-elevated list but not the elevated one.



                                    This question was motivated by the behavior of older versions of Macrium Reflect, which is discussed at https://forum.macrium.com/Topic752-1.aspx The current version of that program now creates those problematic variables at HKU/.DEFAULT/Volatile Environment (AKA HKU/S-1-5-18/Volatile Environment) instead of under the HKCU key.






                                    share|improve this answer














                                    It is not very clear exactly how the environment variables are set in a newly created elevated process, but most of them come from the current user's existing set (as shown by the non-elevated cmd.exe SET command), as well as any that exist in the user's HKCU/Volatile Environment registry key, which have been created since the start of the current login session (or current instance of Explorer?) and are not shown in the non-elevated SET list. There are a few variables in my Windows 10 which occur in the non-elevated list but not the elevated one.



                                    This question was motivated by the behavior of older versions of Macrium Reflect, which is discussed at https://forum.macrium.com/Topic752-1.aspx The current version of that program now creates those problematic variables at HKU/.DEFAULT/Volatile Environment (AKA HKU/S-1-5-18/Volatile Environment) instead of under the HKCU key.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Dec 6 at 21:42

























                                    answered Dec 6 at 21:00









                                    kreemoweet

                                    3,5621214




                                    3,5621214






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Super User!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f477344%2fwhere-do-the-environment-variables-for-an-elevated-cmd-exe-process-come-from%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        Plaza Victoria

                                        Puebla de Zaragoza

                                        Musa