Problem Statement: What is the most elegant and robust way to test if Cygwin
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
Some quick potential solutions:
- I can compare the value of some environmental variables. By quick look of
envoutput 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 specifically
id -Gnshows different groups if run as administrator. In my Windows 7 machine I have
rootgroups 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?