Defrag Tools #132 - PATH

Sign in to queue

Description

In this episode of Defrag Tools, Andrew Richards and Chad Beeder bring sense the to Windows Search Path (%PATH%).

Timeline:
[00:00] - Getting the %PATH%; set PATH or path
[01:25] - path | clip
[01:56] - Leverage Excel to organize the PATH
[02:21] - Data | Convert Text to Columns - Delimiter Semicolon
[03:03] - Paste Special | Transpose
[03:50] - Remove Duplicates
[03:58] - Sort
[25:12] - Put them in a logical order (most important first)
[06:38] - Copy-Paste into Notepad
[06:57] - Search-Replace TAB with Semicolon
[07:18] - Set the new %PATH% - This PC | Properties, Win+Pause, Win-X-Y
[09:04] - Process Monitor - View the OS searching though the folders...
[10:38] - "Bit Rot"
[12:38] - Email us your issues at defragtools@microsoft.com

Embed

Download

Download this episode

The Discussion

  • User profile image
    dandy

    I totally forgot about this:  Years ago I threw together a tiny WinForms utility that broke down the %PATH% values and loaded them in a grid control, that a user could then sort/re-order/delete/add to by dragging/dropping from Explorer, and validate the entire thing (verify the folders actually exist, look for duplicated entries, etc) at the click a button.  It also split it into two groups (current user path vs system path).

    If I remember correctly, the only thing I never implemented was the very last step you'd naturally take--that is, write the final result to the actual environment.  I think the blocker was that I wasn't sure what was the "cleanest" way to programmatically make the change permanent, so I just had a button that copied the final string to the clipboard, which I then manually pasted into the System Properties/Advanced dialog box.

    Obviously, to write back the system-wide value, I'd probably have to run my utility as an admin, but I can live with that.  I know the values exist in the registry, but that feels like a hack.  They're also exposed in WMI (Win32_Environment), but the class doesn't expose any method to make a change.

    Chad/Andrew:  What do you figure ought to be the best way to commit changes to %PATH% programmatically?

  • User profile image
    City17​Citizen

    I think for system/user variables management is easier to use something like Rapid Environment Editor.

  • User profile image
    windev

    @dandy: I'd just call C:\Windows\System32\setx.exe with the new value. Might not be the best way, but it's easy.

    User:
    setx PATH <newstring>

    Machine:
    setx /m PATH <newstring>

  • User profile image
    dandy

    @windev:  I completely forgot about SETX.  You're right, it's probably the least "hack-y" way of doing it.  Now, if only I could find the source for my utility...

  • User profile image
    Snakiej

    Take care when you move the the MSSQL Server Tools around, with this you might hit the older version of dtexec over the newer one. And the newer one can work with the old one, but not vice versa. So I suggest putting the 120\Tools\Binn above the 110\Tools\Binn. 

Add Your 2 Cents