Subject: Re: Test for Windows Administrator permissions from Cygwin terminal|script?
From: Mark Geisert via Cygwin <[email-masked]>
Cc: [email-masked]
Date: Fri, 18 Aug 2023 01:49:18 -0700
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>

Backwoods BC via Cygwin wrote:
> On Thu, Aug 17, 2023 at 7:01 PM Martin Wege via Cygwin
> <[email-masked]> wrote:
>> How can I find out whether the current Cygwin terminal has
>> Administrator rights? I want to safeguard our admin scripts with a
>> simple test and bail out with an error if someone wants to do admin
>> stuff (say: regtool) without admin privileges.
>>
>> Thanks,
>> Martin
> 
> I don't know if this is the official method, but it works for me:
> 
> ##### Shell Options
> # Elevated privilege windows have $SESSIONNAME set
> if [ "$SESSIONNAME" == "" ] ;then
>    printf -v adminPmt '[\u2022Admin\u2022] '
> else
>    export adminPmt=""
> fi

I see the opposite on my machine.  Admin window has empty $SESSIONNAME, non-Admin 
window has "Console".

What I do locally is check the output of the 'id' command.  If group 
544(Administrators) is present, that's a window with Admin rights.  Inside .bashrc 
I have a simple grep test on the output of 'id' to set PS1 (shell prompt) 
appropriately.

..mark

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple