Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an environment variable from the system configuration with a batch file

I need to remove system variables from client workstations. I have 500+ clients, so I want to provide batch file to user to run himself to delete the system variables.

like image 830
user73628 Avatar asked Sep 24 '09 16:09

user73628


2 Answers

The setx command with an empty string value doesn't delete it. And that is not just nitpicking, because the logic is quite different. Because if the user specific variable overrides a global variable, then it is not possible to remove the user specific variable and have the global variable "become active" again. The empty string user specific variable blocks the global variable. One need to actually DELETE it (using the Evironment Variables window) to achieve that.

I just today tried this, with the global variable JAVA_HOME being overridden by a user specific JAVA_HOME. It was not possible to make the global varialble active again without deleting the user specific variable completely. And so far I have not seen a method to do that from the command line or batch script.

(Not enough reputation points to add comment to the above answer about setx, so have to add my own answer...)

like image 186
user1921254 Avatar answered Oct 08 '22 09:10

user1921254


You will need to modify this registry key:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment

Changes are effective after rebooting.

like image 26
Eric J. Avatar answered Oct 08 '22 09:10

Eric J.