public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Mark Geisert <mark@maxrnd.com>
Cc: cygwin@cygwin.com
Subject: Re: Test for Windows Administrator permissions from Cygwin terminal|script?
Date: Fri, 18 Aug 2023 01:49:18 -0700	[thread overview]
Message-ID: <a1d6ff78-2b87-9111-8339-f0ce6d6050cd@maxrnd.com> (raw)
In-Reply-To: <CAKwdsS_Q93_Z0E2cM2iw+DZRvB0DaR6YSi9frod_uh7aoCMxUA@mail.gmail.com>

Backwoods BC via Cygwin wrote:
> On Thu, Aug 17, 2023 at 7:01 PM Martin Wege via Cygwin
> <cygwin@cygwin.com> 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

  reply	other threads:[~2023-08-18  8:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  2:01 Martin Wege
2023-08-18  2:18 ` Backwoods BC
2023-08-18  8:49   ` Mark Geisert [this message]
2023-08-18  8:59     ` Mark Geisert
2023-08-18 22:00 ` Doug Henderson
2023-08-19  8:14 ` ASSI
2023-08-19 17:33   ` Bill Stewart
2023-08-24 16:24   ` Martin Wege
2023-08-25  9:42     ` Corinna Vinschen
2023-08-24 13:01 ` Andrew Schulman
2023-08-24 14:52   ` Bill Stewart
2023-08-24 18:46     ` Bill Stewart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1d6ff78-2b87-9111-8339-f0ce6d6050cd@maxrnd.com \
    --to=mark@maxrnd.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).