/build/static/layout/Breadcrumb_cap_w.png

Script to append /Delete the path of the envirionment variable

'************************************************************
'Script to Append the PATH variable.
'************************************************************
Dim ExistingPath, NewPath
Set oShell = WScript.CreateObject("WScript.Shell")
Set oEnv = oShell.Environment("SYSTEM")

'* Add your Path Entry Here *
ExistingPath = oEnv("PATH")
NewPath = ExistingPath & ";" & "C:\Program Files\IBM\SQLLIB\BIN"
oEnv("PATH") = NewPath 'WRITE NEW PATH, INCLUDING OLD ONE

'************************************************************
'Script to Remove the appended PATH variable.
************************************************************

Dim ExistingPath, NewPath
Set oShell = WScript.CreateObject("WScript.Shell")
Set oEnv = oShell.Environment("SYSTEM")

'* Mention the Path Entry here which u want to remove *
ExistingPath = oEnv("PATH")
path1 = ";C:\Program Files\IBM\SQLLIB\BIN"
var2 = Replace(ExistingPath,path1,"")
oEnv("PATH") = var2

0 Comments   [ + ] Show comments

Answers (2)

Posted by: sk 16 years ago
Senior Yellow Belt
0
Great

I once made the misstake to use

shell.ExpandEnvironmentStrings("%PATH%")

instead of your method and that changes %SystemRoot%\system32 to c:\windows\system32

One could also use

shell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path")

but I let Wise do the job...

Recently I found out (no idea why) that on win2k/citrix the values that a CMD box give are not active after an
MSI installation, a logoff was really needed although nothing was changed in the registry.
Posted by: anonymous_9363 16 years ago
Red Belt
0
ORIGINAL: sk
Recently I found out (no idea why) that on win2k/citrix the values that a CMD box give are not active after an
MSI installation, a logoff was really needed although nothing was changed in the registry.
That's because of what I have recently dubbed The Circle Of Life: Lazy ==> Microsoft Developers ==> Lazy.

When a change is made to the System path, the WI engine fails to send the relevant message to the rest of the system (unlike when you add it manually via Control Panel). That is the reason why I almost *never* use System variables but User ones: they are propogated immediately.

Note also that the script shown fails to check whether the entry being made already exists. How many times have I seen folder names repeated over and over in a PATH statement? Lots, mostly (strangely enough) at the hands of IBM software installs. Once you add that code to the script, don't iorget that you should also add handling for the short path name, too, in case that was used.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ