extending PATH on Windows?

Ulli Horlacher framstag at rus.uni-stuttgart.de
Wed Feb 17 12:49:11 EST 2016

Thorsten Kampe <thorsten at thorstenkampe.de> wrote:

> By the way: there is a script called `win_add2path.py` in your Python 
> distribution

I have 
"Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC
v.1500 32 bit (Intel)] on win32"
and there is no "win_add2path.py"

But I found another solution:

I need the extended PATH only for cmd.exe: users shall run my program
(a compiled executable) without having to enter the full path.

At startup cmd.exe runs a script which is defined by the registry variable
AutoRun in "HKCU\Software\Microsoft\Command Processor"

I set this variable with:

  rc = "HKCU\Software\Microsoft\Command Processor"
  ar = "%USERPROFILE%\Desktop\autorun.cmd"
  system('reg add "%s" /v AutoRun /d "%s"' % (rc,ar))

and write into autorun.cmd:


This command extends PATH only for this cmd.exe instance.
This is all I need!

Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum IZUS/TIK         E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/

More information about the Python-list mailing list