WSH Script to add or replace system path variable
filed in other on Jun.23, 2010
strNewPath =”d:\newpath;”
strPathToReplace =”f:\pathToReplace;”
‘********************************* SET YOUR PATH ABOVE************************
‘Gregor Stefka
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = “.”
strKeyPath = “SYSTEM\CurrentControlSet\Control\Session Manager\Environment”
strValueName = “Path”
Set oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, strValueName,strValue
bAllreadySet = InStr(1, strValue, strNewPath, 1)
‘Wscript.Echo “The OldPath is: ” & strValue
‘Only add if its not set:
If bAllreadySet = 0 then
If strPathToReplace =”” or InStr(1, strValue,strPathToReplace, 1) = 0 then
strNewPath = strNewPath & strValue
Else
strNewPath = Replace(strValue, strPathToReplace, strNewPath)
End If
‘ write the path
oReg.SetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strNewPath
‘Wscript.Echo “The New Path is: ” & strNewPath
End If
Leave a Reply
You must be logged in to post a comment.