Path: csiph.com!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 13:02:21 -0600 Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de flhnBPlqb3vL5N9yRdAg6g6s3HN4TLHFodMQMz8hIbpg== 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; 'received:209.85.223': 0.03; 'startup': 0.05; 'exit': 0.07; 'subject:Windows': 0.09; '"%s"': 0.09; '"%s"\'': 0.09; 'cmd': 0.09; 'operator,': 0.09; 'overwrite': 0.09; 'path)': 0.09; 'wed,': 0.15; '"&"': 0.16; "(it's": 0.16; '2016': 0.16; 'concatenate': 0.16; 'parentheses': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'registry': 0.16; 'sentinel': 0.16; 'set,': 0.16; 'wrote:': 0.16; 'runs': 0.18; 'variable': 0.18; 'cc:2**0': 0.20; 'skip:" 30': 0.20; "user's": 0.22; 'am,': 0.23; 'defined': 0.23; 'feb': 0.23; 'header :In-Reply-To:1': 0.24; 'script': 0.25; 'command': 0.26; 'message- id:@mail.gmail.com': 0.27; 'this.': 0.28; 'exists,': 0.29; 'extending': 0.29; 'that.': 0.30; 'e.g.': 0.30; "can't": 0.32; 'run': 0.33; 'option.': 0.33; 'file': 0.34; 'add': 0.34; 'that,': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'instance': 0.35; 'path': 0.35; 'skip:p 30': 0.35; 'received:209.85': 0.36; 'to:addr :python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'done.': 0.37; 'received:209': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60 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=c28Xm9CAiASo0ExkNqPzb+I6GYkahIVMUdj8Gz2gMPA=; b=pUfSmGoegxJ2jTBfEuygVoEqZolru5X3bPyiEF0/PssBgHDralYpc79gX6cgWwH3iM WJ4o8QDVDvRgwQAXS9hs99zm7kmt4gkGqea618p2nA3A/MQIi1pnosbMTWbcL5v8Gtp0 soM6hZ44m2IuCpZwr+Q+2+cC6hyWkXIFpveYISjlVVUYHcWyuwzGTwWZxlWSNW0dqhGA qEiJPrv4480zWLJrZuCNlyr86+a0z7ww64xqfITYFYupB4eXXnZ1VwGBSJlzaF6ETl4B Si3ROomWbbtRyL7Zz7M3dNkvbT7AEg+IyGmb8n1PrSEIwVShECw/+tLaWdaqzq/bVEtJ 0lCw== 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=c28Xm9CAiASo0ExkNqPzb+I6GYkahIVMUdj8Gz2gMPA=; b=Zk8rTJs+VkiFKL0q1CxHt9kg/oe6prqm0LQQ3VznctygTKuKPuyiZDiTVmvSq793vR mpoDfN6dOS/RrSnqcD4q5XzaAjy6Qzngq883efPOBPQRSvJSCYctwMoEWgobpM9NOLZi kim4HNND/fKiausndGhhwZVgTCgEYx2fwMAK3M73npmOAXc8EsR41K98ex1zviGWhwYP Q5F64g64sF/pgPpMLdoZAcSUpuyiKJc1FpS5GIILimjss1ixx+zHDpiQvwCTAahXP+7l CtmmafmwzFLV7tXHBBBlrTjP2WZD/6LlS8g3FVh4rFzhLXhZQLYm0jf1wWOhd0bSI+Ed vZYQ== X-Gm-Message-State: AG10YORMjhlyv+m6x3q5FdDOutUauBPQhoD9YW9YNSpRYsBsUUttQI+Vc9SztM/BWi2haEGkGmPoG0wuei8JTQ== X-Received: by 10.107.10.158 with SMTP id 30mr4786351iok.73.1455735781421; Wed, 17 Feb 2016 11:03:01 -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:103062 On Wed, Feb 17, 2016 at 11:49 AM, Ulli Horlacher 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) 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.