ofek / userpath

Cross-platform tool for adding locations to the user PATH, no elevated privileges required!
MIT License
151 stars 20 forks source link

Userpath Breaks the Path Environment Variable on Windows #27

Closed DG-SHeather closed 4 years ago

DG-SHeather commented 4 years ago

Describe the bug

if userpath is run on Windows, it breaks the Path environment variable by changing the HKCU\Environment\Path value from a REG_EXPAND_SZ type to a REG_SZ type. This will cause all paths that contain environment variables within the path to not be expanded and therefore not searched.

How to reproduce

C:\>reg query HKCU\Environment /v Path

HKEY_CURRENT_USER\Environment
    Path    REG_EXPAND_SZ    C:\Users\su_heathes\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\su_heathes\AppData\Local\Programs\Python\Python38\;C:\Users\su_heathes\AppData\Local\Programs\Python\Launcher\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Users\su_heathes\AppData\Roaming\npm;C:\Users\su_heathes\.local\bin

C:\>userpath append 'c:\test'
Success!

C:\>reg query HKCU\Environment /v Path

HKEY_CURRENT_USER\Environment
    Path    REG_SZ    C:\Users\su_heathes\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\su_heathes\AppData\Local\Programs\Python\Python38\;C:\Users\su_heathes\AppData\Local\Programs\Python\Launcher\;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Users\su_heathes\AppData\Roaming\npm;C:\Users\su_heathes\.local\bin;H:\'c:\test'

Expected behavior

Leave the HKCU\Environment\Path value as a REG_EXPAND_SZ type.

Suggested Solution

In interface.py, change winreg.SetValueEx(key, 'PATH', 0, winreg.REG_SZ, new_path) to winreg.SetValueEx(key, 'PATH', 0, winreg.REG_EXPAND_SZ, new_path)

Userpath version

1.4.0

ofek commented 4 years ago

Oh my. Fixing...

ofek commented 4 years ago

https://pypi.org/project/userpath/1.4.1/

ofek commented 4 years ago

Can you confirm the fix?

DG-SHeather commented 4 years ago

Yep thats fixed @ofek. Thanks,

ofek commented 4 years ago

Thank you!