How to get access to environment variables in Windows?

12,936

Solution 1

I'm not sure about whether your rights will allow it but you can try setting the path for a command window with path = %PATH%;newdir; if it works, it will last until the command window is closed. This may be ok for you if you are mostly working at the command line.

There is also the setx tool that you could try if your rights allow you to install it.

Here is some additional information about the environment variables that may prove useful.

Solution 2

Yes, you can create your own environment.

  • GUI:
    • System Properties -> Advanced -> Environment Variables
      • Or, if you don't have access this way, you might be able to get it by running rundll32 sysdm.cpl,EditEnvironmentVariables from the Run window or commandline.
    • Click Add, enter PATH as name and %PATH%;mynewdir as value. (You don't need to include %PATH% via the GUI, especially if you are editing an existing PATH variable; it just holds the string value of PATH before you made edits.)
    • This is the only method that ensures instant availability to all future processes launched by Explorer, without the need to re-login.
  • Kinda GUI:
    • regedit -> HKEY_CURRENT_USER\Environment
    • Right-click, New -> Expandable String Value
  • CLI:
    • reg add hkcu\environment /v PATH /t reg_expand_sz /d %%PATH%%;mynewdir
    • Doubled %% is required to prevent %%PATH%% from being expanded by shell.
Share:
12,936

Related videos on Youtube

Jonas
Author by

Jonas

I'm a Computer Science student.

Updated on September 17, 2022

Comments

  • Jonas
    Jonas over 1 year

    I have borrowed a laptop with Windows XP from a company that I will do a project for. They say that I have almost Admiinistrator rights on the computer so that I can install software.

    Now I have installed a few development tools, but I need to add a few things to the PATH environment variable. But I don't seem to have permissions to edit the PATH environment variable. Is there any way I could workaround this? Could I create a personal environment variable PATH that is used instead?

  • Jonas
    Jonas over 13 years
    I tried this and tested setx but I got this message: Access is denied. I don't think it's possible to fix this. I have to contact the company. Thanks anyway.
  • user1686
    user1686 over 13 years
    The correct syntax in cmd shell is set path=%path%;newdir - note the set prefix and no whitespace around =
  • Neal
    Neal over 13 years
    @grawity The set is deliberately missing. Jonas explained in the question that he wasn't allowed to use set to set the path. I wasn't sure where the block came in so I was pointing out a way to change the path for the current command window, with the hope that this might not be prevented by the lack of admin rights. I didn't bother listing the standard methods of changing the path because I read the question which told me they didn't work.
  • user1686
    user1686 over 13 years
    The question does not mention set anywhere. There's more than one way of editing environment; maybe Jonas was talking about the GUI. (Besides, it is not possible to disable the set builtin except by patching cmd.exe, and even then there are many ways to get around it.)