Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to make an 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:

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?

Thanks in advance!

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

share|improve this question
    
(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 say setx 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 Jul 3 '13 at 21:04
    
It occurs to me that you may be able to solve your problem by peeking in the registry. –  Scott Jul 3 '13 at 21:05
    
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.) –  Scott Jul 18 '13 at 23:36

1 Answer 1

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:

http://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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.