Wednesday 15 January 2014

Append a Location to the Path Environment Variable using vbscript

http://blogs.technet.com/b/heyscriptingguy/archive/2006/08/28/how-can-i-append-a-location-to-the-path-environment-variable.aspx


strComputer = "." <----- or changes this "." to computer name e.g. "computer-01"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Environment Where Name = 'Path'")

For Each objItem in colItems
    strPath = objItem.VariableValue & ";C:\Scripts\"
    objItem.VariableValue = strPath
    objItem.Put_
Next