Discussion:
Remove system environment variable using command line ?
(too old to reply)
Vilius Mockûnas
2009-06-12 10:19:01 UTC
Permalink
Hello,

How do I remove system environment variable using command line ?
For example I can add it using:
setx y 10 -m
But from setx documentation:
"You cannot use setx to remove values added to the local or system
environments."

(I know how to remove using GUI but this is not the case)

thanks
Vilius
Pegasus [MVP]
2009-06-12 10:40:12 UTC
Permalink
Post by Vilius Mockûnas
Hello,
How do I remove system environment variable using command line ?
setx y 10 -m
"You cannot use setx to remove values added to the local or system
environments."
(I know how to remove using GUI but this is not the case)
thanks
Vilius
The following script will first set, then remove the system variable %XVar%:
Set wshShell = CreateObject("WScript.Shell")
Set wshSEnv = wshShell.Environment("System")
sMyVar = "XVar"
wshSEnv(sMyVar) = "Vilius"
WScript.Echo "Variable " & sMyVar & " is now set to Vilius"
wshSEnv.Remove sMyVar

Loading...