-1

I want the user to input the path of the bin directory and then store that path to system variable path

i tried this

 set /p path = Please specify the path to the bin folder
 echo Path is set to = %path%

does not seems to work

Basically i want the user to enter the path and that entered path gets permanently stored in the system variable 'path' hope i am more clear now

user1926152
  • 235
  • 2
  • 8
  • 13

2 Answers2

1

You may get help from the answer of this question: Setting a system environment variable from a Windows batch file?

It says you should use setx

Community
  • 1
  • 1
Mahesh Bansod
  • 1,493
  • 2
  • 24
  • 42
  • problem with setx is, we have 2 PATH variables: one system wide & one user's own. I don't want to add only to user's local `path` variable. – anishsane Dec 27 '12 at 11:15
  • 1
    @anishsane Check out the `/M` option for `setx /?`. It will do what you want. http://technet.microsoft.com/en-us/library/cc755104(v=ws.10).aspx – David Ruhmann Dec 27 '12 at 21:10
  • 1
    When we read PATH variable, it's concatenated version of both PATH variables. I want to set `new_user_path=old_user_path;my_dir` NOT `new_user_path=old_path;my_dir` – anishsane Dec 28 '12 at 05:58
0

Remove the spaces. The set command doesn't trim, so the input is actually stored in a variable named path<space>.

This is something you should be able to spot easily if you call set without parameters. You will see an extra variable that has this extra space.

BUT NOTE: path is already an existing variable, containing the search path for the command session. You'd better use a different name altogether if you don't want to overwrite that variable.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • and how do i append the user entered path to the system path variab;e – user1926152 Dec 27 '12 at 09:51
  • 1
    `set path=%path%;%yourtemporaryvariable%` – GolezTrol Dec 27 '12 at 10:16
  • much easy i was trying with registries and all – user1926152 Dec 27 '12 at 10:22
  • Hmm. I think this is not persistent. That is, if your command session closes, the value will be gone. I see you added a paragraph about persistency to your question that wasn't there before. – GolezTrol Dec 27 '12 at 10:24
  • 2
    With `setx` you should be able to make it persistent, I think, but there's another limit. If I run `setx path="%path%;c:\added\path" \m`, I get an error "ERROR: Length of the command line argument should not exceed 255 characters". And that is a problem, since you %path% variable is likely to be longer (it is on my PC). Long story short: Batch is not the right place to modify this variable. Also, you would need administrator rights for your script. – GolezTrol Dec 27 '12 at 10:28