Skip navigation

Q. How can I use a script to add a folder to the end of the system path?

I have scripted AddPath.vbs to add a folder to the system path.

The syntax for using AddPath.vbs is:

cscript //nologo <Drive:>\ScriptPath\AddPath.vbs Folder

Where Folder is the folder path you wish to add, like C:\Util or "C:\Program Files\Log Parser 2.2".

AddPath.vbs contains:

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count  1 Then Wscript.Echo "Syntax: cscript //nologo AddPath.vbs Folder"
if oArgs.Count  1 Then Wscript.Quit
NewFold = oArgs(0)
strComputer = "."
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 & ";" & NewFold
    objItem.VariableValue = strPath

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.