Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Permanently change the PATH from within a DOS Batch File  (Read 14432 times)

0 Members and 1 Guest are viewing this topic.

mroilfield



    Mentor
  • Thanked: 42
    • Yes
    • Yes
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 11
Re: Permanently change the PATH from within a DOS Batch File
« Reply #15 on: April 13, 2009, 10:11:39 AM »
This Path would be the default search path for any system commands such as those located in C:\Windows\System32

Examples:

cmd.exe
msconfig.
append.exe
attrib.exe
calc.exe
expand.exe
ftp.exe
runonce.exe
rundll.exe
sysedit.exe
edit.com
format.com
command.com

etc...etc...

without this path(s) windows would not opperate well, if at all.



Thanks for the info
You can't fix Stupid!!!

Dias de verano

  • Guest
Re: Permanently change the PATH from within a DOS Batch File
« Reply #16 on: April 13, 2009, 11:29:46 AM »
I have SETX.EXE in my default path (C:/Windows/System32) but have no clue how this command is to do what I am asking.



setx /?

or setx -i


gh0std0g74



    Apprentice

    Thanked: 37
    Re: Permanently change the PATH from within a DOS Batch File
    « Reply #17 on: April 13, 2009, 06:48:19 PM »
    I'd like to permanently change the PATH of a Windows XP system using a DOS Batch file.
    you can use command line registry tools or vbscript  to change the registry setting
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path.

    iONik

      Topic Starter


      Beginner

      Re: Permanently change the PATH from within a DOS Batch File
      « Reply #18 on: April 13, 2009, 08:19:24 PM »
      you can use command line registry tools or vbscript  to change the registry setting
      HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path.

      From the registry I exported to a file EvVar.reg

      Code: [Select]
      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
      "ComSpec"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
        74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,\
        00,6d,00,64,00,2e,00,65,00,78,00,65,00,00,00
      "FP_NO_HOST_CHECK"="NO"
      "NUMBER_OF_PROCESSORS"="1"
      "OS"="Windows_NT"
      "Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
        00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
        53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
        00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
        53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,62,00,65,00,6d,\
        00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
        25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,5c,00,73,00,79,00,73,00,62,\
        00,61,00,74,00,73,00,3b,00,43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,\
        57,00,53,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,\
        00,69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,\
        68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,00,00
      "PATHEXT"=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1"
      "PROCESSOR_ARCHITECTURE"="x86"
      "PROCESSOR_IDENTIFIER"="x86 Family 6 Model 13 Stepping 8, GenuineIntel"
      "PROCESSOR_LEVEL"="6"
      "PROCESSOR_REVISION"="0d08"
      "TEMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
        00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00
      "TMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
        25,00,5c,00,54,00,45,00,4d,00,50,00,00,00
      "windir"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
        00,25,00,00,00


      Now would I just need an edited version with aditional environmental variables and import the reg file and restart for changes to take effect?

      Or would I really only need the following code as the Path is all that would be altered?

      Code: [Select]
      Windows Registry Editor Version 5.00

      [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
      "Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
        00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
        53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
        00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
        53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,62,00,65,00,6d,\
        00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
        25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,5c,00,73,00,79,00,73,00,62,\
        00,61,00,74,00,73,00,3b,00,43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,\
        57,00,53,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,\
        00,69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,\
        68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,00,00

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Permanently change the PATH from within a DOS Batch File
      « Reply #19 on: April 13, 2009, 08:22:44 PM »
      To change the PATH variable permanently :

      My Computer - Properties - Advanced - Environment Variables

      or

      Control Panel - System - Advanced - Environment variables

      Reboot.



      Which part did you miss the first and second time?
      I was trying to dereference Null Pointers before it was cool.

      gh0std0g74



        Apprentice

        Thanked: 37
        Re: Permanently change the PATH from within a DOS Batch File
        « Reply #20 on: April 13, 2009, 09:07:41 PM »
        From the registry I exported to a file EvVar.reg

        Code: [Select]
        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
        "ComSpec"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,\
          74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,63,\
          00,6d,00,64,00,2e,00,65,00,78,00,65,00,00,00
        "FP_NO_HOST_CHECK"="NO"
        "NUMBER_OF_PROCESSORS"="1"
        "OS"="Windows_NT"
        "Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
          00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
          53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
          00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
          53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,62,00,65,00,6d,\
          00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
          25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,5c,00,73,00,79,00,73,00,62,\
          00,61,00,74,00,73,00,3b,00,43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,\
          57,00,53,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,\
          00,69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,\
          68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,00,00
        "PATHEXT"=".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1"
        "PROCESSOR_ARCHITECTURE"="x86"
        "PROCESSOR_IDENTIFIER"="x86 Family 6 Model 13 Stepping 8, GenuineIntel"
        "PROCESSOR_LEVEL"="6"
        "PROCESSOR_REVISION"="0d08"
        "TEMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
          00,25,00,5c,00,54,00,45,00,4d,00,50,00,00,00
        "TMP"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
          25,00,5c,00,54,00,45,00,4d,00,50,00,00,00
        "windir"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
          00,25,00,00,00


        Now would I just need an edited version with aditional environmental variables and import the reg file and restart for changes to take effect?

        Or would I really only need the following code as the Path is all that would be altered?

        Code: [Select]
        Windows Registry Editor Version 5.00

        [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
        "Path"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
          00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,\
          53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,\
          00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,\
          53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,62,00,65,00,6d,\
          00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,\
          25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,5c,00,73,00,79,00,73,00,62,\
          00,61,00,74,00,73,00,3b,00,43,00,3a,00,5c,00,57,00,49,00,4e,00,44,00,4f,00,\
          57,00,53,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,\
          00,69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,\
          68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,00,00

        hey man, are you going to change the PATH variable permanently that often? if not, just do it once through the control panel.
        otherwise, i think you should read up on how reg.exe works.

        Dias de verano

        • Guest
        Re: Permanently change the PATH from within a DOS Batch File
        « Reply #21 on: April 14, 2009, 12:19:13 AM »
        I smell a potential rat. Why monkey with the registry scriptomatically, and why is he putting the values like that in hex? Why not use the manual method of Control Panel / My Computer, or else a script with SETX?



        iONik

          Topic Starter


          Beginner

          Re: Permanently change the PATH from within a DOS Batch File
          « Reply #22 on: April 14, 2009, 07:53:25 AM »
          I smell a potential rat. Why monkey with the registry scriptomatically, and why is he putting the values like that in hex? Why not use the manual method of Control Panel / My Computer, or else a script with SETX?




          If I am way off base by not just simple using "My Computer - Properties - Advanced - Environment Variables" then your sens of smell is extremely damaged. Don't read between the lines. Paranoia may tell you that something is there, but all that something is really just air.

          I often do more OS installations than I would like and am simply trying to simplify the monkey work. I merely want to create a file with helpful batch files and such whose path is part of the system variable.

          Registry file in HEX: That's the way it exported, that's all, no rats..,nothin' but air.

          I guess the question is: does not the method of "My Computer - Properties - Advanced - Environment Variables" merely change the registry, and this is why I'd need a restart?

          "or script with SETX" would anyone care to elaborate on this?


          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: Permanently change the PATH from within a DOS Batch File
          « Reply #23 on: April 14, 2009, 07:55:07 AM »
          Setx?
          I was trying to dereference Null Pointers before it was cool.

          iONik

            Topic Starter


            Beginner

            Re: Permanently change the PATH from within a DOS Batch File
            « Reply #24 on: April 14, 2009, 08:20:13 AM »
            SETX...

            SETX MYPATH %PATH%
            Sets the value of MYPATH to the CURRENT value of the PATH environment variable.

            In other words set MYPATH =
            %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\WINDOWS\system32\WindowsPowerShell\v1.0


            SETX MYPATH ~PATH~
            Sets the value of MYPATH to ALWAYS be equal to the value of the PATH environment
            variable even in the event that the PATH variable changes.


            SETX Registry Examples:
            -------------------
            SETX TZONE -k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName
            Sets the value of TZONE to the above key ie. "Central Standard Time"

            The above examples seem only to create then set a variable to an existing value. I would like to do the opposite, set a known value from a different known variable. Or am i misreading this, hence the reason I came here in the first place...

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Permanently change the PATH from within a DOS Batch File
            « Reply #25 on: April 14, 2009, 08:21:34 AM »
            "set" followed by the name of  the variable prints that variable.
            I was trying to dereference Null Pointers before it was cool.

            iONik

              Topic Starter


              Beginner

              Re: Permanently change the PATH from within a DOS Batch File
              « Reply #26 on: April 14, 2009, 08:34:35 AM »
              Alright, Alright...

              I'll Keep you guys from sharing a little information and help. Don't want you to fall off the precipice you stand on.

              It is often said that the evil one sees in others is nothing but a mirror reflection of self. Thus by being so intent on exposing a "rat" in someone else it merely exposes the "rat" in oneself.

              If my task could only be done via "My Computer - Properties - Advanced - Environment Variables" and no other way, then all would be said and done and I should have posted in the Windows XP Forum. But since I keep getting other possibilities from the gallery, I keep getting the suspicion that It can indeed be done another way, using batch code, script code, SETX code... which is why I posted in this forum for help.

              But I will forgive you all for your poor sense of smell and not prod you any further......................

              Cheers!

              « Last Edit: April 14, 2009, 09:12:05 AM by iONik »

              gh0std0g74



                Apprentice

                Thanked: 37
                Re: Permanently change the PATH from within a DOS Batch File
                « Reply #27 on: April 14, 2009, 08:46:43 AM »
                if you have Perl , you can use Win32::TieRegistry module
                Code: [Select]
                use Win32::TieRegistry;
                $path = $Registry->{"LMachine/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/Path"};
                $path = $path . ";c:\\test_directory";
                $Registry->{"LMachine/SYSTEM/CurrentControlSet/Control/Session Manager/Environment/Path"} = $path;
                otherwise, using setx is very straightforward, i don't see why it can't work for you.

                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: Permanently change the PATH from within a DOS Batch File
                « Reply #28 on: April 14, 2009, 08:54:28 AM »
                otherwise, using setx is very straightforward, i don't see why it can't work for you.

                apparently we're supposed to give him a whole *censored* script.
                I was trying to dereference Null Pointers before it was cool.

                iONik

                  Topic Starter


                  Beginner

                  Re: Permanently change the PATH from within a DOS Batch File
                  « Reply #29 on: April 15, 2009, 03:41:46 PM »
                  Here's my mountain of code to do the job I was after...

                  Code: [Select]
                  @echo off
                  set vara=%PATH%
                  set varb=;%SystemRoot%\sysfiles
                  set varc=%vara%%varb%
                  setx PATH %varc% -m
                  set vara=
                  set varb=
                  set varc=

                  not really sure the set vara=, set varb=, set varc= is necessary.