extending PATH on Windows?
Ulli Horlacher
framstag at rus.uni-stuttgart.de
Wed Feb 17 15:29:37 EST 2016
eryk sun <eryksun at gmail.com> 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:
> >
> > set PATH=%PATH%;%USERPROFILE%\Desktop
>
> The AutoRun command (it's a command line, not a script path)
A script path is a legal command line, too.
> gets run for every instance of cmd.exe
Yes, this is the intended trick!
> 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.
Having "%USERPROFILE%\Desktop" twice in PATH is not a problem.
> 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).
Good hint, thanks!
> Use winreg for this.
system("reg ...") works for me and is easier :-)
--
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