This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Environment variables & system privilages


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@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]