Announcement

Collapse
No announcement yet.

Modify PATH Environment Variable (was: New to scripting)

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

  • Modify PATH Environment Variable (was: New to scripting)

    Hi all,

    i'm fairly new to scripting of any sort, i would like to start by saying sorry if i'm asking a question that has already been asked i have seen the thread that covers part of what i'm asking but my real issue is this.


    i have a client who wants to have ";R:\" added to the "path" system variable which i know has been covered and i get how to do

    my question is.

    is there a way to check if the string i want added is already a part of the "path" system variable and to only add it if it DOESN'T exist.

    i have been able to check if the string exists using this

    echo %path% | find /c /i ";R:\"

    and to add the string i can use

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set WshEnv = WshShell.Environment("SYSTEM")
    WshEnv("Path") = WshEnv("Path") & ";R:\"

    which i thank andrew hinson for
    http://forums.petri.com/showthread.php?t=4347

    this is where i am stuck, i don't know how to add the string if it doesn't exist or not add it if it does.

    this is really urgent, any help would be extremely appreciated

    Thanks

    Byron

  • #2
    Re: Modify PATH Environment Variable (was: New to scripting)

    FYI, you can use setx.exe to modify environment variables, or pathman.exe to specifically modify the path (supports add and delete, at both the system and user level). Not sure if pathman already checks if it's in there though.
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Modify PATH Environment Variable (was: New to scripting)

      i've tried to use the setx.exe utility, how can i use it in a login script?

      i would prefer using a vbs script to do it all or just a batch script
      is that possible to do it all through either one or using a combo if need be?

      Comment


      • #4
        Re: Modify PATH Environment Variable (was: New to scripting)

        Originally posted by bron88 View Post
        i've tried to use the setx.exe utility, how can i use it in a login script?

        i would prefer using a vbs script to do it all or just a batch script
        By running setx as part of your script... not sure what else to tell you?
        Gareth Howells

        BSc (Hons), MBCS, MCP, MCDST, ICCE

        Any advice is given in good faith and without warranty.

        Please give reputation points if somebody has helped you.

        "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

        "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

        Comment


        • #5
          Re: Modify PATH Environment Variable (was: New to scripting)

          Originally posted by bron88 View Post
          is there a way to check if the string i want added is already a part of the "path" system variable and to only add it if it DOESN'T exist.
          There is an other tool similar to SetX it is called SETENV.exe
          When running SetEnv to make a change it will broadcast a notification to all of the windows in the system (This allows other running applications—for example, Explorer.exe—to be notified of your change). Except for the current environment where the script itself is running in (the parent) that was executing setenv.

          Note, you can find two different tools with the same name SETENV.exe on the internet. Both can do almost the samething.
          You can download here the one that has the most features:
          - http://www.codeguru.com/cpp/w-p/win3...cle.php/c10849
          I know this version of setenv will only add new values to the PATH environment variable if they don't already exists.

          From a command prompt the syntax is:
          "C:\Utills\SetEnv.exe" -a PATH %"R:\
          - in a batch you have to double that Percent sign.
          - in a vbscript you have to double all the Quote signs.

          (batch):
          Code:
          @echo off
          Set "addToPATH=R:\"
          "C:\Utills\SetEnv.exe" -a PATH %%"%addToPATH%
          (vbscript):
          Code:
          With WScript.CreateObject("WScript.Shell")
             addToPATH = "R:\"
             intRC = .run _
             ("""C:\Utills\SetEnv.exe"" -a PATH %""" _
             & addToPATH, 0, true)
          End With
          you can place the SetEnv.exe on a share to make it available for the computer Startup script that is running it.

          \Rems
          Last edited by Rems; 6th February 2009, 00:39.

          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