Re: Remove environment variable

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Michael Harris \(MVP\) (mikhar_at_mvps.org)
Date: 01/07/05


Date: Fri, 7 Jan 2005 14:30:26 -0800

stev379 wrote:
> Hello,
> The script below works to delete the value of the path, but not
> the path variable itself. Our machines have no User environment Path
> variable set, only the System Path variable. An altered version of
> the script below creates the Path variable and sets the value. I
> only need the path when I run a specific app and don't want to leave
> the path variable lingering. Is there a way to completely remove the
> Path user environment variable?

The WshEnvironment object has a Remove method...

Set colUsrEnvVars = objShell.Environment("USER")
colUsrEnvVars.Remove("PATH")

> I'm not married to this particular script. If there is a better way
> to perform this (or the action of creating the path variable to begin
> with, I'm open to ideas...preferably in vbs.
>
> 'Begin script
>
> Set objShell = WScript.CreateObject("WScript.Shell")
> Set colUsrEnvVars = objShell.Environment("USER")
>
> colUsrEnvVars("PATH") = colUsrEnvVars("")
>
> Wscript.Echo "Current User Path = " & colUsrEnvVars("PATH")
>
> 'End script
>
> Thanks for any help or suggestions.
> -Steve

-- 
Michael Harris
Microsoft.MVP.Scripting


Relevant Pages

  • Indiana to Eastern Time Zone Exchange Appointment fixer scripts
    ... It fixes both the time zone tags and start times ... deployed in a 9000 user environment, a 600 user environment, and most ... some having an "unexpected error" with the script exiting early. ... Please test test test until you can't test any more before using ANY ...
    (microsoft.public.exchange.admin)
  • Re: Login script with admin priveleges
    ... The whole point of a logon script ... is to set up the user environment, not to run silly EXE files as the ... what's the difference between a silly EXE file and a serious one and is ...
    (microsoft.public.scripting.vbscript)
  • Re: Login script with admin priveleges
    ... The whole point of a logon script ... is to set up the user environment, not to run silly EXE files as the ... what's the difference between a silly EXE file and a serious one and is ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Login script with admin priveleges
    ... The whole point of a logon script ... is to set up the user environment, not to run silly EXE files as the ... what's the difference between a silly EXE file and a serious one and is ...
    (microsoft.public.windowsxp.wmi)
  • Remove environment variable
    ... The script below works to delete the value of the path, ... Our machines have no User environment Path variable set, ... Set colUsrEnvVars = objShell.Environment ...
    (microsoft.public.windows.server.scripting)