extending PATH on Windows?

eryk sun eryksun at gmail.com
Wed Feb 17 14:02:21 EST 2016

On Wed, Feb 17, 2016 at 11:49 AM, Ulli Horlacher
<framstag at rus.uni-stuttgart.de> wrote:
> 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:

The AutoRun command (it's a command line, not a script path) gets run
for every instance of cmd.exe, unless cmd is started with the /D
option. This includes the CRT's system() function. Your batch file
needs to set a sentinel variable such as YOUR_APP_AUTORUN that, if
set, makes the batch file exit without extending PATH if it was
already done.

Also, you can't just overwrite a user's AutoRun command like that. If
a command currently exists, you have to concatenate your command with
the existing command using parentheses and the "&" operator, e.g.
(previous_command) & (your_command). Use winreg for this.

More information about the Python-list mailing list