setx.exe and reg: Set / remove Windows environment variables permanently

Ever want to set or remove Windows environment variables permanently within a command file, so you can use it in other command sessions? Use setx en reg !

setx.exe is an application that comes with the Windows XP Service Pack 2 Support Tools (not sure if it comes standard in Windows Server 2003) and inserts the environment setting in the Windows Registry (HKCU\Environment). The environment setting however will not be available in current open sessions, only in new opened sessions.

The reg command is available without some Pack (at least on XP). You can use it to remove registry keys, but the environment setting will not removed from current open sessions. You could also use it to add environment settings…

To add entries

setx oracle_sid prod
reg add HKCU\Environment /v oracle_sid /d prod /f

To delete entries

reg delete HKCU\Environment /v oracle_sid /f

More info

SETX – http://ss64.com/nt/setx.html
REG – http://ss64.com/nt/reg.html

Good luck!

Windows XP Service Pack 2 Support Tools

Tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *