Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: eryk sun Newsgroups: comp.lang.python Subject: Re: extending PATH on Windows? Date: Wed, 17 Feb 2016 15:17:46 -0600 Lines: 41 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de YNR3nOr1/TCSjoMm++lnFAd+SbthmAaqdXdEYOZkt0xw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'modify': 0.04; 'append': 0.07; 'shortcut': 0.07; 'subject:Windows': 0.09; 'any.': 0.09; 'command.': 0.09; 'operator,': 0.09; 'overwrite': 0.09; 'path)': 0.09; 'script,': 0.09; ':-)': 0.12; 'wed,': 0.15; 'value.': 0.15; '"&"': 0.16; "(it's": 0.16; '2016': 0.16; 'concatenate': 0.16; 'executed,': 0.16; 'function?': 0.16; 'parentheses': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'registry': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'machine': 0.21; 'parse': 0.22; 'simpler': 0.22; "user's": 0.22; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; 'script': 0.25; 'install': 0.25; 'command': 0.26; 'message-id:@mail.gmail.com': 0.27; 'this.': 0.28; 'exists,': 0.29; 'path,': 0.29; 'starts': 0.29; 'that.': 0.30; 'too.': 0.30; 'e.g.': 0.30; 'query': 0.30; 'another': 0.32; "can't": 0.32; 'run': 0.33; 'thanks!': 0.34; 'file': 0.34; 'previous': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'instance': 0.35; 'path': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209.85.213': 0.37; "won't": 0.38; 'received:209': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'export': 0.63; 'more': 0.63; 'legal': 0.66; 'prompt': 0.79 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=qOu/hO71i2Wf+3wNvJsVCgidpsSKdl0YbRGOgo7Hoxg=; b=w9i2/EsrgJ8bQk32By1pMKMDjOpcx7y1V6IxRpgam2YJmSct9yaYod7ToFmOnIh5sF nHc8uMUDnHm5IAF9Fh9rwPOv6Gxyq/KrlG9Y++OweSUJOoNSrj9f4uRfUwYi+2M426Tg lBHLy7NpA9gofke8fIU7MWEcWMYhhqncrXzpcGO4YG1s29mYu7pmMqUXjEdT4Sv7SPNM ZF+jJOsSwwcxfV/6spd3glLfP3phu0JiN0NkTJmh5v2i/MRVtekye5KXGbLuFDZcSHPp DNcJXQ144kgh4ksw7afeY9rH+n4fuPImD0x3wMiCjMOXOeniohAaBRqFkp/90MMOHCph e6Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=qOu/hO71i2Wf+3wNvJsVCgidpsSKdl0YbRGOgo7Hoxg=; b=WT6VLYNR5/pdRCo7adkl/LXH1jTEix8Ws0UmDBDgHZSrWQbVrii+46SSJTXDzOOK5S h6WkWnhV4NZDoNjd/jZe9yMhvJdoKbdxsq7yABsqgEcHE3Bbe0sc5ngSw3ICENqa6sMT RRLrT4PTUW2YMgpUsyftdqWAKT6XL/WOX9a1YanyVOlK4vCNh8hNSXLzrlR3lETtQfOd laN3glF30cEk9sb23TSnFJE73WJKTj2x8rTl2jNHReX3AAE0XGfiU88etQ+o5X1HrIh2 e+Mn5+hozceXZKYrhXFttdY5X+m44jPvnthF+reyaYah+sM8QfI3eVPEQa2OKmkdAbbP /Mgg== X-Gm-Message-State: AG10YOQEAKZSSbY7nI0jd6J00vjJa4C957cP6pVyamJT534HAqzk0d2W5L//kbFroPfCiqMwaTVCUqa6LHgmFg== X-Received: by 10.50.222.98 with SMTP id ql2mr9460717igc.55.1455743906548; Wed, 17 Feb 2016 13:18:26 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103072 On Wed, Feb 17, 2016 at 2:29 PM, Ulli Horlacher wrote: > eryk sun wrote: >> > >> > 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. If the registry value were just a script path, you'd have to modify your script to chain to the previous script, if any. Since it's a command line you can simply use the & operator to append another command. >> gets run for every instance of cmd.exe > > Yes, this is the intended trick! Do you really intend for your batch file to be run every time cmd.exe is executed, including every time that every program on the machine calls the CRT system() function? Why don't you just install a shortcut to a batch file that starts a command prompt with the extended PATH? >> 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 :-) system('reg...') won't be able to do that unless you export the key to a .reg file and parse the existing AutoRun value. It would be simpler to use subprocess.check_output('reg query ...'), but simpler still and more reliable to just call QueryValueEx.