Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
Brilliant! Thank you. –  TallGuy Nov 25 '09 at 22:36

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

share|improve this answer
    
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 '09 at 22:17

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.

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.