Remove environment variable
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Remove environment variable

 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming
Author Message
stev379
Guest





Posted: Fri Jan 07, 2005 8:49 am    Post subject: Remove environment variable Reply with quote

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?
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
Back to top
Torgeir Bakken (MVP)
Guest





Posted: Fri Jan 07, 2005 6:04 pm    Post subject: Re: Remove environment variable Reply with quote

stev379 wrote:

Quote:
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?
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.
Hi


'--------------------8<----------------------
Set oShell = CreateObject("WScript.Shell")

On Error Resume Next
oShell.RegDelete "HKCU\Environment\Path"
On Error Goto 0
'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Back to top
Michael Harris (MVP)
Guest





Posted: Sat Jan 08, 2005 4:30 am    Post subject: Re: Remove environment variable Reply with quote

stev379 wrote:
Quote:
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")


Quote:
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
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB