Problem Statement: What is the most elegant and robust way to test if Cygwin mintty
bash
session is "Run as adminstrator"?
Why, specifically? I have typically several mintty
terminals open when using Windows (mintty
does not have tabs). The most awkward is when I need to find a terminal window that I started by right-clicking "Run as administrator" when for example I want to run ping
or other one-time procedure. I would like to indicate the "run as administrator"-ness of the terminal session visually (by changing the bash
shell prompt variable PS1
in my start-up file ~/.bashrc
).
Some quick potential solutions:
- I can compare the value of some environmental variables. By quick look of
env
output there are quite many differences. It is however hard to tell which is most reliable in terms of portability to another Windows machine (perhaps running different version of Windows). id
, more specificallyid -Gn
shows different groups if run as administrator. In my Windows 7 machine I haveAdministrators
androot
groups added to the list. Again, I am not sure if this is portable.- I could try to write a file to a location that would fail as normal user. But I do not want to write any files to strange places - this could in some imagined scenarios be potentially destructive (e.g. failing storage media) and this seems utterly inelegant to my taste.
- Running some Windows program that will indicate by return status or output if the command is run "as administrator". Best would be some with analogous purpose to that of UNIX
id(1)
command (but natively existing in Windows - or Cygwin, but without too far fetched translation of Windows system concepts to POSIX emulated concepts).
Any better or more elegant suggestions? Perhaps cygwin provides a command utility dedicated for this purpose?
Update: 97% duplicate of https://stackoverflow.com/questions/4051883/batch-script-how-to-check-for-admin-rights/ - the difference is just here using bash
instead of (IMHO weird and archaic) Windows cmd.exe
. Please do check the answers and commentaries there.
mintty
that 1. runs as administrator, 2. uses different configuration file with differing color settings and 3. uses an alternative icon. If you describe to general public how to create this, I will give you an upvote (unless you say in your answer that it cannot be done within a script :-).Foo
user group if you wanted.sudo
which is required even if you are running as a root user.