Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <41B305B2.7030805@ieee.org> Date: Sun, 05 Dec 2004 12:57:22 +0000 From: Jason Pearce User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20040910 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Environment variables & system privilages References: <41B1A1C4 DOT 6020102 AT ieee DOT org> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Thanks. This works well enough. But I take it there is no universal command to check for system permissions. The procedure is just try a command that needs system privilages and watch the exit status. Also for the benefit of anyone reading this thread - there was an error in my original post. I dropped the "Environment" key from the registry path for setting system environment variables. It should have read. regtool set -s 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\FOO' 'BAR' Jason Igor Pechtchanski wrote: >On Sat, 4 Dec 2004, Jason Pearce wrote: > > > >>I have two seemingly simple questions that I just can't find the answers >>to. Any assistance would be appreciated >> >>1. What's the "right" way to add add environment variables into the user and >>system maps? >>Currently I am using regtool to manipulate the registry. For instance to set >>an environment variable FOO=BAR I do: >> >>regtool set -s '\HKEY_CURRENT_USER\Environment\FOO' 'BAR' >>or >>regtool set -s 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\FOO' 'BAR' >> >>The first form places it in the user's map, the second in the system >>map. But will this work across patform? Is there a more preferred >>method? >> >> > >Well, that's probably the best you could hope for, if you want system-wide >settings. I'm not aware of any other command-line tool that would set >these. If you only want to set environment variables for Cygwin shells, >you might want to edit /cygwin.bat instead. > > > >>2. How can I test whether my script is running with system privilages? >>ie I want to write a script that installs a mount and sets and environment >>variable. If the script is running with system privilages I want to make the >>change system wide. Otherwise, in the user's profile. >> >> > >Why not try mounting with system privileges first? 'mount' will fail if >it's unable to set mounts, and you can fall back on user mounts. In other >words: > >#!/bin/sh >if mount -tfs d:/projects /projects; then > regtool set -s 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\FOO' 'BAR' >else > # User ony > mount -tfu d:/projects /projects > regtool set -s '\HKEY_CURRENT_USER\Environment\FOO' 'BAR' >fi > > > >>#!/bin/sh >>if [ ??????? ] >>then >> # Sytem wide >> mount -tfs d:/projects /projects >> regtool set -s 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\FOO' 'BAR' >>else >> # User ony >> mount -tfu d:/projects /projects >> regtool set -s '\HKEY_CURRENT_USER\Environment\FOO' 'BAR' >>fi >> >>What do I put in place of the ?????? >> >> > >HTH, > Igor > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/