delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/12/04/17:19:46

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sat, 4 Dec 2004 17:19:35 -0500 (EST)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Jason Pearce <jason DOT pearce AT ieee DOT org>
cc: cygwin AT cygwin DOT com
Subject: Re: Environment variables & system privilages
In-Reply-To: <41B1A1C4.6020102@ieee.org>
Message-ID: <Pine.GSO.4.61.0412041531410.3217@slinky.cs.nyu.edu>
References: <41B1A1C4 DOT 6020102 AT ieee DOT org>
MIME-Version: 1.0

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
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

--
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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019