'************************************************************
'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

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

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.
Answered 11/12/2008 by: sk
Senior Yellow Belt

Please log in to comment
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.
Answered 11/13/2008 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity