Announcement

Collapse
No announcement yet.

add to windows PATH=

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • add to windows PATH=

    Hi
    i would like to know how can i add a new PATH for all my domain computers ?
    not via GPO - it will overide what users allready have

    i need it via logon.vbs

    for example add c:\temp to the PATH=

    Thanks

  • #2
    Re: add to windows PATH=

    Have a read of the following. http://forums.petri.com/showthread.php?t=4347
    1 1 was a racehorse.
    2 2 was 1 2.
    1 1 1 1 race 1 day,
    2 2 1 1 2

    Comment


    • #3
      Re: add to windows PATH=

      Hi

      I did ran this batch file

      "set path=%path%;s:\it"

      when i run it from the command and after i run the Path command i can see what i have added . BUT when i enter System Properties , Envirunment setting the path didnt change , it only changed on the cmd i opend

      why ?

      (my users account are roaming )

      Thanks

      Comment


      • #4
        Re: add to windows PATH=

        You want to add a new environment variable or edit the environment variable.
        Anyway, this script can help you out.
        http://www.microsoft.com/technet/scr...5/hey0318.mspx
        Marcel
        Technical Consultant
        Netherlands
        http://www.phetios.com
        http://blog.nessus.nl

        MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
        "No matter how secure, there is always the human factor."

        "Enjoy life today, tomorrow may never come."
        "If you're going through hell, keep going. ~Winston Churchill"

        Comment


        • #5
          Re: add to windows PATH=

          Originally posted by tulik23 View Post
          how can i add a new PATH for all my domain computers ?
          not via GPO - it will overide what users allready have

          i need it via logon.vbs

          for example add c:\temp to the PATH=
          AFAIK with Group Policy Preferences you should be able also to add folders to the PATH variable w/out overwriting existing values (value type in registry should become/stay REG_EXPAND_SZ to support multiple and/or expandable values).
          When the environmental variable preferences in the GPO is configured at Computer configuration the value will be added to the System environment - or, when configured at User configuration the value will be added to the variable in the user environment.

          All the values of System Environment Variables, User Environment Variables and Volatile Environment Variables will be present in a logon session and available throughout all processes. Variables existing in more than one type of environment with the same name are merged, in that order.

          _
          Originally posted by tulik23 View Post
          I did ran this batch file

          "set path=%path%;s:\it"

          <..> BUT when i enter System Properties , Envirunment setting the path didnt change , it only changed on the cmd i opend

          why ?
          What your batch does is adding the new value for what is called the Process Environment. A process environment variable is set by one process or by one of its subprocesses and only available for the process and any of its subprocesses started after that. This environment is gone when the process and all subprocesses are ended.
          For your batch you'll need the free Microsoft ResKit tool SETX.exe to set environmental variables in the the user or Computer environment.

          _
          Assumming that the first script "logon.vbs" is an user logonscript and not a computer startupscript:
          1. If you use a logon script then (unlike using a startup script) you can only add the value to the User or to the Volatile environment, because normal users are not allowed to change computer configurations ! (note, The user environment (userenv) has a 2048 character limit)
          2. Furthermore, the logon script (also if it is a startup script) should not just add the value at every logon, it should determine first whether or not the item is already added at a previous logon, add only if not exist.

          Since your logon script is a vbscript, you can use a vbscript solution to add an item to the User environment variable, instead of a logon batch that uses setx:
          Code:
          ' This vbscript includes a Sub routine for ADDing
          ' value(s) to an environment variable.
          ' (OPTIONAL, it'd  also be possible to 
          '  include an other Sub routine to be able also to delete values)
          
          Const ENVIRONMENT_VAR  = "PATH"
          COnst ENVIRONMENT_TYPE = "USER"
          
          Dim WSHShell, sEnvVar, arrAddItems
          sEnvVar = "%" & ENVIRONMENT_VAR & "%"
          Set WSHShell = WScript.CreateObject("WScript.Shell")
          
          ' Item to add to the environment. Wrap each item between quotes
          ' (note, Multiple items should be COMMA-separated in the array!)
          arrAddItems = array("c:\temp")
          
          AddToEnv arrAddItems
          
          Sub AddToEnv(AddItems)
             Dim colEnvVars, strVarExpandedFull, arrVarExpandedFull
             Dim strEnvCurrentValues, sAddItem, sCurItem, CompA, CompB
             Dim iVal, PrintableChars, x, i, c, sep, sNewItems
             sep= Empty : sNewItems = Empty
             With WSHShell
               Set colEnvVars = .Environment(ENVIRONMENT_TYPE)
               strVarExpandedFull = .ExpandEnvironmentStrings(sEnvVar)
               arrVarExpandedFull = Split(strVarExpandedFull, ";")
               For x = 0 To Ubound(AddItems)
                 iVal= FALSE
                 sAddItem = Trim(AddItems(x))
                 CompB = LCase(.ExpandEnvironmentStrings(sAddItem))
                 CompB = Replace(Replace(CompB, "/", "\"), chr(34), "")
                 If InStrRev(CompB, "\") = Len(CompB) _
                   Then CompB = Left(CompB, Len(CompB)-1)
          
                 For i = 0 To Ubound(arrVarExpandedFull)
                   sCurItem = Trim(arrVarExpandedFull(i))
                   If Len(sCurItem) >0 Then
                     CompA = LCase(.ExpandEnvironmentStrings(sCurItem))
                     CompA = Replace(Replace(CompA, "/", "\"), chr(34), "")
                     If InStrRev(CompA, "\") = Len(CompA) _
                       Then CompA = Left(CompA, Len(CompA)-1)
                     If CompB = CompA Then iVal= TRUE
                   End If
                 Next
          
                 If iVal= FALSE Then
                   sNewItems = sNewItems & sep & sAddItem
                   Sep = ";"
                 End If
          
               Next
             End With
          
             If Len(sNewItems) >0 Then
               strEnvCurrentValues = colEnvVars(ENVIRONMENT_VAR)
               PrintableChars = False
               For c = 32 to 126
                 If inStr(strEnvCurrentValues, chr(c)) _
                   then PrintableChars = True
               Next
               If sEnvVar <> strEnvCurrentValues Then
                 If PrintableChars = True Then
                   colEnvVars(ENVIRONMENT_VAR) = strEnvCurrentValues & ";" & sNewItems
                 Else
                   colEnvVars(ENVIRONMENT_VAR) = sNewItems
                 End If
               Else
                 colEnvVars(ENVIRONMENT_VAR) = sNewItems
               End If
             End If
          End Sub
          
          Sub RemoveFromVar(DelItems)
             With WSHShell
               Set colEnvVars = .Environment(ENVIRONMENT_TYPE)
               arrEnvCurrentValues = Split(colEnvVars(ENVIRONMENT_VAR), ";")
          
               Dim sep: sep = Empty
               For i = 0 To Ubound(arrEnvCurrentValues)
                 sCurItem = Trim(arrEnvCurrentValues(i))
                 If Len(sCurItem) >0 Then
                   CompA = LCase(.ExpandEnvironmentStrings(sCurItem))
                   CompA = Replace(Replace(CompA, "/", "\"), chr(34), "")
          
                   If InStrRev(CompA, "\") = Len(CompA) _
                     Then CompA = Left(CompA, Len(CompA)-1)
                   iVal = TRUE
                   For x = 0 To Ubound(DelItems)
                     sDelItem = Trim(DelItems(x))
                     CompB = LCase(.ExpandEnvironmentStrings(sDelItem))
                     CompB = Replace(Replace(CompB, "/", "\"), chr(34), "")
                     If InStrRev(CompB, "\") = Len(CompB) _
                       Then CompB = Left(CompB, Len(CompB)-1)
                     If CompB = CompA Then 
                       iVal = FALSE
                       rem wscript.echo CompB
                     End If
                   Next
                   If iVal = TRUE Then
                     sNewItems = sNewItems & sep & sCurItem
                     Sep = ";"
                   End If
                 End If
               Next
             End With
             colEnvVars(ENVIRONMENT_VAR) = sNewItems
          End Sub
          _
          Then there is also a very nice tool called SETENV.EXE.
          This tool offers greater functionality than SETX.EXE in viewing and manipulating the environments. And is much easier to script then the vbs sample above.
          Actually there are at least two different free editions of "SETENV.EXE" that can be found on the internet
          - one is SetEnv by Vincent Fatica
          - an other SetEnv by Jonathan Wilkes.
          Both editions I mensioned are nice tools but note that each edition has its own syntax!! The latter is still supported and updated regularly. The vbscript sample below is using SETENV.exe by Jonathan, download the setup file then you can extract SETENV.exe from it by using 7-Zip (open source software).

          SETENV.EXE can be
          - executed from a command-line,
          - invoked by a vbscript (see sample below)
          - launched from within a batch script (read the "Running SetEnv from a batch file" section on his site).
          - executed from a central share on the network, you dont have to deploy it.

          Sample,
          Add or remove values to an expandable Environment Variable:
          Code:
          ' Download SETENV-Setup.exe from,
          ' http://xanya.net/site/display_code.php?id=2&t=utils
          ' Extract the tool SETENV.exe by Jonathan Wilkes from the setup file.
          ' Copy the tool to a central share on the network.
          
          Dim SetEnvExePath
          Const ENVIRONMENT_VAR  = "PATH"
          Const DELETE = " /Ud"  ' del from *User Env*
          Const ADD    = " /Ua"  ' add to *User Env*
          SetEnvExePath = "\\server\share\SetEnv.exe"
          
          Dim WSHShell, arrDelItems, arrAddItems
          
          If Not IsObject(WSHShell) _
             Then Set WSHShell = CreateObject("WScript.Shell")
          
          ' Delete value (enter none, one or multiple items,
          ' comma-separate multiple items in the array)
          arrDelItems = array()
          Update_environment ENVIRONMENT_VAR, DELETE, arrDelItems
          
          ' Add value (enter none, one or multiple items,
          ' comma-separate multiple items in the array)
          arrAddItems = array("c:\test")
          Update_environment ENVIRONMENT_VAR, ADD, arrAddItems
          
          Sub Update_environment(EnvType, Options, arrVal)
             Dim sVal, i, rc, REG_EXPAND_SZ
             With WSHShell
               REG_EXPAND_SZ = "%"
               If isArray(arrVal) Then
                 For i = 0 to UBound(arrVal)
                   sVal = Trim(arrVal(i))
                   If Len(sVal) > 0 Then
                     ' append(%) to existing env and refresh environment
                     rc = .Run(SetEnvExePath & " " & Options & " " & EnvType _
                       & " " & REG_EXPAND_SZ & """" & sVal & """", 0, True)
                   End If
                 Next
               End If
             End With
          End Sub

          \Rems
          Last edited by Rems; 5th October 2009, 20:56.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment

          Working...
          X