3
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?
1
HKCU\Environment
for user vars. andHKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
for system.vars. PATH combines/concatenates them – barlop – 2015-05-03T14:35:36.883(1) No, it’s not a duplicate; at least not of that question. (2) I believe that you’ve phrased the question badly.
SETX
does work the way you want. But if you saysetx PATH "C:\MyStuff;%PATH%"
, then you are copying the system path into the user path. What you should be asking is “How do I get the value of a user environment variable: specifically,PATH
, and I mean only the user part of it, not all of%PATH%
? Alternatively, how can I append something to a user environment variable without knowing its current value?” – Scott – 2013-07-03T21:04:48.230It occurs to me that you may be able to solve your problem by peeking in the registry. – Scott – 2013-07-03T21:05:42.420
1I got it! Use
reg query HKCU\Environment /v path
to get just the user part of thePATH
environment variable. (Write it to a file, and then parse the file, or wrap aFOR
loop around it.) – Scott – 2013-07-18T23:36:28.253