Friday, July 13, 2018

command line - Why didn't SETX update my PATH when I tried adding VLC? (Windows 7)



I'm attempting to add VLC to the PATH variable on a Windows 7 setup, so that it can be called from cmd using vlc vs "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe".




Using set, the PATH can be modified for the current instance of cmd, but I'd like this to persist through reboots, be applicable for all users on the system (if possible), and to use CLI tools native to Windows 7. I tried setx (in both non-admin and run-as-administrator cmd windows) as referenced in this question, and rebooted. However, after running path, the vlc path doesn't show up (in the variable string), and vlc returns the error: 'vlc' is not recognized as an internal or external command, operable program or batch file.



Here are some snippets from the run-as-admin cmd.exe instance after reboot ... I check the path:




C:\Windows\system32>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\pkg-vc10-x64\GeographicLib-1.23\bin;C:\Program Files (x86)\XPlan\system;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\python27;C:\python27\scripts;C:\Program Files (x86)\QuickTime\QTSystem\




I don't see the VLC path there, so I try setx again...





C:\Windows\system32>setx PATH=%PATH%;"C:\Program Files (x86)\VideoLAN\VLC"
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s). Type "SETX /?" for usage.




Looking at the PATH, I see...





  • PATH=C:\ProgramData\Oracle\Java\javapath



    • C:\Windows\system32

    • C:\Windows

    • C:\Windows\System32\WindowsPowerShell\v1.0\

    • C:\Program Files\Intel\WiFi\bin\

    • C:\Program Files\Common Files\Intel\WirelessCommon\

    • C:\strawberry\c\bin

    • C:\strawberry\perl\site\bin

    • C:\strawberry\perl\bin


    • C:\pkg-vc10-x64\GeographicLib-1.23\bin

    • C:\Program Files (x86)\XPlan\system

    • C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\

    • C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\

    • C:\python27

    • C:\python27\scripts

    • C:\Program Files (x86)\QuickTime\QTSystem\






... and checking in a regular-user cmd window, the results below ...





  • PATH=C:\ProgramData\Oracle\Java\javapath


    • C:\Windows\system32

    • C:\Windows


    • C:\Windows\System32\Wbem

    • C:\Windows\System32\WindowsPowerShell\v1.0\

    • C:\Program Files\Intel\WiFi\bin\

    • C:\Program Files\Common Files\Intel\WirelessCommon\

    • C:\strawberry\c\bin

    • C:\strawberry\perl\site\bin

    • C:\strawberry\perl\bin

    • C:\pkg-vc10-x64\GeographicLib-1.23\bin

    • C:\Program Files (x86)\XPlan\system

    • C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\


    • C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\

    • C:\python27

    • C:\python27\scripts

    • C:\Program Files (x86)\QuickTime\QTSystem\

    • C:\Ruby22-x64\bin

    • C:\Windows\system32

    • C:\Windows

    • C:\Windows\System32\Wbem

    • C:\Windows\System32\WindowsPowerShell\v1.0\

    • C:\Program Files\Intel\WiFi\bin\


    • C:\Program Files\Common Files\Intel\WirelessCommon\

    • C:\strawberry\c\bin

    • C:\strawberry\perl\site\bin

    • C:\strawberry\perl\bin

    • C:\pkg-vc10-x64\GeographicLib-1.23\bin





Why can't I add a path variable to PATH via setx? The error says the string is already there, and yet doesn't show it for either admin or standard user...




Edit to add: I also referenced this question in my original research: https://stackoverflow.com/questions/9546324/adding-directory-to-path-environment-variable-in-windows


Answer



Why didn't SETX update my PATH




C:\Windows\system32>setx PATH=%PATH%;"C:\Program Files (x86)\VideoLAN\VLC"
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s). Type "SETX /?" for usage.





Your setx syntax is wrong:




  • Get rid of the =



    set uses =, setx does not.


  • Put the quotes " around the second parameter (the 'value').



    The second parameter should be quoted if it contains spaces and %PATH% always contains spaces.





You should be using:



setx PATH "%PATH%;C:\Program Files (x86)\VideoLAN\VLC"





Syntax





SETX [/s Computer [Credentials]] Variable Value [/m]

SETX [/s Computer [Credentials]] [Variable] /k RegistryPath [/m]

SETX [/s Computer [Credentials]] /f FileName {[Variable] {/a L,T | /r oL,oT "SearchString"} [/m] | /x} [/d Delimiters]



Source setx







Further Reading




  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.

  • setx - Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU).


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...