"Vilius Mockūnas" <> wrote in message
news:...
> 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
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
|