Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

set path definitely

66 views
Skip to first unread message

orpy

unread,
Feb 12, 2009, 1:10:56 PM2/12/09
to
in win2000/XP/Vista we can set the "path" environment variable using the
GUI; doing this, the path variable remains the same after each reboot:
forever.

how can I set the PATH variable in this way, from commandline?

MattWil

unread,
Feb 12, 2009, 1:25:15 PM2/12/09
to

I haven't tested this but you might be able to use REG and add it to

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment\Path

Make sure to use REG_EXPAND_SZ as the type if you have any environment
variables in the path name.

01MDM

unread,
Feb 12, 2009, 1:53:05 PM2/12/09
to
> how can I set the PATH variable in this way, from commandline?

Three ways:

1:
reg add hkcu\environment /v Path /t reg_sz /v "Path\to\Folder 1;Path\to
\Folder 2" /f
logoff
(warning - it can rewrite PATH param if it has defined. By default its
not)

2:
start cmd from the batch where PATH-variable must be defined

3:
use some utilities to set/add path from command line.

orpy

unread,
Feb 12, 2009, 3:29:16 PM2/12/09
to

thanks matt!

orpy

unread,
Feb 12, 2009, 3:28:47 PM2/12/09
to

01MDM wrote:
>> how can I set the PATH variable in this way, from commandline?
>
> Three ways:
>
> 1:
> reg add hkcu\environment /v Path /t reg_sz /v "Path\to\Folder
> 1;Path\to \Folder 2" /f
> logoff
> (warning - it can rewrite PATH param if it has defined. By default its
> not)

after reboot this is permanent?



> 2:
> start cmd from the batch where PATH-variable must be defined

this is only for the session, or for the batch, right?



> 3:
> use some utilities to set/add path from command line.

... do you have one preferred?

Pegas...@yahoo.com

unread,
Feb 13, 2009, 9:31:04 AM2/13/09
to

Here are two of them:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)

orpy

unread,
Feb 17, 2009, 8:23:26 PM2/17/09
to

Pegas...@yahoo.com wrote:


>>> 3:
>>> use some utilities to set/add path from command line.
>>
>> ... do you have one preferred?
>
> Here are two of them:
> setx.exe (Win2000 Resource Kit)
> setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)

yes!!!
setx is now part of Vista! :)
so i think this could be considered "standard" :)

Tom Del Rosso

unread,
Feb 21, 2009, 5:19:49 PM2/21/09
to

"orpy" <or...@urcaurca.tirulero> wrote in message
news:4994662f$0$848$4faf...@reader5.news.tin.it

By 'command line' I assume you mean batch file. If not you would jet type
the right syntax, but in a batch file you want to find the right syntax for
either 2k or xp. This subroutine does that.

It also uses both reg and setx to avoid any trouble.

If you only use reg.exe then the variable won't appear in the environment
until the next restart.

If you only use setx.exe the only thing that can go wrong is if the same
variable gets set in the user environment, which overrides the machine
environment. In that case you need reg.exe to delete the user variable (see
rem statements).

This subroutine was meant for certain other environment variables, but is ok
for the path. For the purpose this was written for, I wanted to remove user
variables, but you could remove the part with reg and just use the part that
finds the right syntax for setx (line 24 onward).


[1]
[2] :SetMachine
[3]
[4] rem sets or clears variable in machine environment, allowing for
differences in setx.exe and reg.exe syntax between OS versions
[5] rem also removes variable from user environment
[6]
[7] rem parameter %1 is variable name
[8] rem parameter %2 is value
[9]
[10] rem clear variable from user environment, then use reg to delete
user-variable from registry because setx replaces value with null string,
but doesn't delete variable
[11] rem the null user variable still overides machine variable
[12] rem setx is also needed because environment keeps the deleted variable
until logoff if only reg is used
[13] rem try syntax of XP version of reg first, which causes 2k version to
return 5000
[14]
[15] if "%~1"=="" goto :end
[16]
[17] setx %1 ""
[18] rem try XP syntax of reg.exe
[19] reg delete HKCU\Environment /v %1 /f>nul 2>&1
[20] if %errorlevel%==5000 (
[21] rem then 2K syntax
[22] reg delete HKCU\Environment\%1 /force>nul 2>&1
[23] )
[24] rem for machine environment use syntax of 2k or XP version of setx.exe
[25] setx -i>nul 2>&1
[26] if errorlevel 1 (
[27] rem quotes added in case %2 is a null string; setx always removes
quotes
[28] setx %1 "%~2" /M
[29] ) else (
[30] setx %1 "%~2" -m
[31] )
[32] rem set local variable for use in the current batch process
[33] set %1=%~2
[34] goto :eof


--

Reply in group, but if emailing add one more
zero, and remove the last word.


orpy

unread,
Mar 18, 2009, 6:46:16 PM3/18/09
to

Tom Del Rosso wrote:
> "orpy" <or...@urcaurca.tirulero> wrote in message
> news:4994662f$0$848$4faf...@reader5.news.tin.it
>> in win2000/XP/Vista we can set the "path" environment variable using
>> the GUI; doing this, the path variable remains the same after each
>> reboot: forever.
>>
>> how can I set the PATH variable in this way, from commandline?
>
> By 'command line' I assume you mean batch file. If not you would jet
> type the right syntax, but in a batch file you want to find the right
> syntax for either 2k or xp. This subroutine does that.

> This subroutine was meant for certain other environment variables,
> but is ok for the path. For the purpose this was written for, I
> wanted to remove user variables, but you could remove the part with
> reg and just use the part that finds the right syntax for setx (line
> 24 onward).

many thanks, tom!

0 new messages