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


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/


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