11

The group policy in our environment overwrites the PATH variable every time I log on and, as I run a 'non-standard' computer, it gets it completely wrong (C:\Windows vs C:\WINNT, missing directories etc). Currently, I manually change it every time I log on, but that is starting to get tiresome.

If I use the SET command to change the PATH variable in a batch file, it only has local scope so the change only applies to the commands in the batch file.

set PATH=C:\WINNT;C:\WINNT\System32
set PATH

This batch file will output the new path, but if I run set PATH on the command line afterwards, it will still be the original path.

How do I set the global PATH environment in a batch file? Or is there another technique I can use?

3 Answers 3

10

You can use the setx command:

setx PATH C:\WINNT;C:\WINNT\System32 /m

Setx is available in Windows 2003 and later, but can be downloaded in the Support Tools for Windows XP.

0
0

This is edited in system preferences -> [Environment variables]. There you add paths to $PATH

1
  • That's what I'm doing at the moment, every time I log on. I want to do it in a batch file so it can be done automatically.
    – TallGuy
    Nov 25, 2009 at 22:17
0

To set your path in the registry so that it propagates to , you can create a PowerShell script that uses some variation of this:

[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";newpart", "user")

But when I tried it just now then looked at System Properties>Environment Variables it not only added my test path, but doubled the existing one. So that problem needs to be worked out.

Based on this page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .