Adding a directory to the PATH environment variable in Windows

前端 未结 18 1228
我在风中等你
我在风中等你 2020-11-21 05:13

I am trying to add C:\\xampp\\php to my system PATH environment variable in Windows.

I have already added it using the Environment Varia

相关标签:
18条回答
  • 2020-11-21 05:52

    In a command prompt you tell Cmd to use Windows Explorer's command line by prefacing it with start.

    So start Yourbatchname.

    Note you have to register as if its name is batchfile.exe.

    Programs and documents can be added to the registry so typing their name without their path in the Start - Run dialog box or shortcut enables Windows to find them.

    This is a generic reg file. Copy the lines below to a new Text Document and save it as anyname.reg. Edit it with your programs or documents.

    In paths, use \\ to separate folder names in key paths as regedit uses a single \ to separate its key names. All reg files start with REGEDIT4. A semicolon turns a line into a comment. The @ symbol means to assign the value to the key rather than a named value.

    The file doesn't have to exist. This can be used to set Word.exe to open Winword.exe.

    Typing start batchfile will start iexplore.exe.

    REGEDIT4
    ;The bolded name below is the name of the document or program, <filename>.<file extension>
    
    [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\Batchfile.exe]
    
    ; The @ means the path to the file is assigned to the default value for the key.
    ; The whole path in enclosed in a quotation mark ".
    
    @="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\""
    
    ; Optional Parameters. The semicolon means don't process the line. Remove it if you want to put it in the registry
    
    ; Informs the shell that the program accepts URLs.
    
    ;"useURL"="1"
    
    ; Sets the path that a program will use as its' default directory. This is commented out.
    
    ;"Path"="C:\\Program Files\\Microsoft Office\\Office\\"
    

    You've already been told about path in another answer. Also see doskey /? for cmd macros (they only work when typing).

    You can run startup commands for CMD. From Windows Resource Kit Technical Reference

    AutoRun

    HKCU\Software\Microsoft\Command Processor
    
    Data type Range Default value
    REG_SZ  list of commands  There is no default value for this entry.
    

    Description

    Contains commands which are executed each time you start Cmd.exe.

    0 讨论(0)
  • 2020-11-21 05:54

    Checking the above suggestions on Windows 10 LTSB, and with a glimpse on the "help" outlines (that can be viewed when typing 'command /?' on the cmd), brought me to the conclusion that the PATH command changes the system environment variable Path values only for the current session, but after reboot all the values reset to their default- just as they were prior to using the PATH command.

    On the other hand using the SETX command with administrative privileges is way more powerful. It changes those values for good (or at least until the next time this command is used or until next time those values are manually GUI manipulated... ).

    The best SETX syntax usage that worked for me:

    SETX PATH "%PATH%;C:\path\to\where\the\command\resides"
    

    where any equal sign '=' should be avoided, and don't you worry about spaces! There isn't any need to insert any more quotation marks for a path that contains spaces inside it - the split sign ';' does the job.

    The PATH keyword that follows the SETX defines which set of values should be changed among the System Environment Variables possible values, and the %PATH% (the word PATH surrounded by the percent sign) inside the quotation marks, tells the OS to leave the existing PATH values as they are and add the following path (the one that follows the split sign ';') to the existing values.

    0 讨论(0)
  • 2020-11-21 05:55

    Regarding point 2 I'm using a simple batch file that is populating PATH or other environment variables for me. Therefore, there is no pollution of environment variables by default. This batch file is accessible from everywhere so I can type:

    c:\>mybatchfile
    -- here all env. are available
    c:\>php file.php
    
    0 讨论(0)
  • 2020-11-21 05:55

    As trivial as it may be, I had to restart Windows when faced with this problem.

    I am running Windows 7 x64. I did a manual update to the system PATH variable. This worked okay if I ran cmd.exe from the stat menu. But if I type "cmd" in the Windows Explorer address bar, it seems to load the PATH from elsewhere, which doesn't have my manual changes.

    (To avoid doubt - yes, I did close and rerun cmd a couple of times before I restarted and it didn't help.)

    0 讨论(0)
  • 2020-11-21 05:56

    If you run the command cmd, it will update all system variables for that command window.

    0 讨论(0)
  • 2020-11-21 05:57

    On Windows 10, I was able to search for set path environment variable and got these instructions:

    1. From the desktop, right-click the very bottom-left corner of the screen to get the Power User Task Menu.
    2. From the Power User Task Menu, click System.
    3. In the Settings window, scroll down to the Related settings section and click the System info link.
    4. In the System window, click the Advanced system settings link in the left navigation panel.
    5. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.
    6. In the Environment Variables window (pictured below), highlight the Path variable in the System variables section and click the Edit button. Add or modify the path lines with the paths you want the computer to access. Each different directory is separated with a semicolon, as shown below:

    C:\Program Files;C:\Winnt;C:\Winnt\System32

    The first time I searched for it, it immediately popped up the System Properties Window. After that, I found the above instructions.

    0 讨论(0)
提交回复
热议问题