Access/modify the user Path variable, not system Path

6,084

So, I suppose I should have indicated I am using Inno-setup to create the installer file. Inno-setup has a built-in registry modifier to change user path variables. I found the answer at:

https://stackoverflow.com/questions/3304463/how-do-i-modify-the-path-environment-variable-when-running-an-inno-setup-install

The steps there describe how to set environment variables. Good luck anyone trying to do this!

Share:
6,084

Related videos on Youtube

Qwerty Keyboard
Author by

Qwerty Keyboard

Updated on September 18, 2022

Comments

  • Qwerty Keyboard
    Qwerty Keyboard over 1 year

    I am trying to make an Inno-setup installer for a program and my workplace doesn't allow us "regular" users to modify the system environment. In an effort to get around the restrictions, I'm trying to add my program's .exe to the user Path variable instead of the system Path. Since this is in an installer, it basically will need to be done via command line prompts.

    I have been looking around and found the SETX command a while ago, and while it does indeed modify the user's Path, it also includes the entire system Path. For example:

    setx PATH "C:\MyStuff;%PATH%"
    

    will return this user Path:

    C:\MyStuff;[The entire system PATH];[What was in the user path before]
    

    While this technically fulfills my requirement, I feel like this is very poor practice to make the user's Path massive and redundant with the system Path.

    So here's my question:

    Using command line prompts, how can I modify only the user's Path variable?

    EDIT: Appears to be a duplicate of Prevent Windows System %PATH% from being prepended to user %PATH?

    • Scott - Слава Україні
      Scott - Слава Україні almost 11 years
      It occurs to me that you may be able to solve your problem by peeking in the registry.
    • Scott - Слава Україні
      Scott - Слава Україні almost 11 years
      I got it! Use reg query HKCU\Environment /v path to get just the user part of the PATH environment variable. (Write it to a file, and then parse the file, or wrap a FOR loop around it.)
    • barlop
      barlop about 9 years
      HKCU\Environment for user vars. and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment for system.vars. PATH combines/concatenates them