extending PATH on Windows?

Thorsten Kampe thorsten at thorstenkampe.de
Tue Feb 16 08:38:42 EST 2016


* Ulli Horlacher (Tue, 16 Feb 2016 12:38:44 +0000 (UTC))
> 
> Thorsten Kampe <thorsten at thorstenkampe.de> wrote:
> > * Ulli Horlacher (Tue, 16 Feb 2016 08:30:59 +0000 (UTC))
> > > I need to extend the PATH environment variable on Windows.
> > 
> > 1. Add the path component yourself into HKEY_CURRENT_USER and make 
> > sure it's not there already (pure Python).
> 
> Preferred!
> What is HKEY_CURRENT_USER? Another environment variable?

It's a hive in the Windows registry and the equivalent of `~/.*` in 
Linux terms (HKEY_LOCAL_MACHINE[/Software] being the equivalent of 
`/etc`). The fact that you're asking indicates that you should read 
about that in advance. 

The task itself is definitely not that hard. Maybe someone has 
already asked at StackOverflow. But the devil's in the detail.

Some things to consider

- Python is not by default installed on Windows, so you have to use a 
way to run your script without (PyInstaller for instance).

- by default there is no entry in HKCU, so you have to create it 
first (under HKEY_CURRENT_USER\Environment).

- you need to create the correct type (REG_SZ, null-terminated 
string)

- Windows paths are semicolon separated (not colon).

- Windows only module for the Registry: 
https://docs.python.org/3/library/winreg.html

Thorsten



More information about the Python-list mailing list