X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B282E383FDD5
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1692396063;
	bh=/9uQq3zUX7VelXDHLk94HRlmAaN3hm5/JOxKdF7GV9U=;
	h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=Qd8rhCQG+GG0eVzKvPQ8c8wI3n1Q7ZhEJcOk05z7S07cmWI/j2cLn2w5J6aoskFdn
	 Saz+C/N/2RAe+aegXsgzT4TBOcI105ftottKQ4rYUHEYvTgEnWGPzGQv/cewKOsuPP
	 nCixNSIXN8n/BKsg/z7xvGS107V1pALJF0aWwGqo=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BDCDC3856254
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20221208; t=1692396022; x=1693000822;
 h=content-transfer-encoding:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=bjj/U53dz9QRYimTQXC0fzF1ebEpXYbuLl1VH/iBqNc=;
 b=IGnpwu44ABFrPSgN8fCAACPzS39g3ij5xzcMOBxZmbHspcGkf1URfdluLvvQWHj7mz
 DDN1D0l8hawWeKOs/EfDXUX8Q19VlsZ56gUCsq8NaFrLVcTCP55FflQcD27XN53+v8Hq
 XHTfB558Q0xvy6PIzNSExKRShDXlug96Z1pIGcH2Cf5+22vtqdyVlrbYgoNis58DgIOp
 k4A7IDZpk2S8MFddy/CK+vNJzzCoXUySwX9l9wZDgw4OuHcnUo75TziVokxbNVFXHQZw
 wLKNTO0EAEPx6ftpM7qeIx5GIQ4hwXgAbKKnrrmPvlG94WUn8y5ujAQmUnJM8keAdCIv
 enug==
X-Gm-Message-State: AOJu0YwAccphK0a5x7u+tvf+SitoWqKZ7MnylSTr6H2NesicJV8XwpQ6
 OnTzigltD5sm/pvS3OL+LO1p4VCHmaMRGxwy9c6SgbYbjBw=
X-Google-Smtp-Source: AGHT+IFszDQa+LFYke8vhDC1+4+2ldRDe4zWh7USgSUvjY3yOACjKJ27PtCwoxPUN7mCMTgw3elbG+rGyfdNovgqh0k=
X-Received: by 2002:a17:907:7781:b0:987:5761:2868 with SMTP id
 ky1-20020a170907778100b0098757612868mr304697ejc.11.1692396021958; Fri, 18 Aug
 2023 15:00:21 -0700 (PDT)
MIME-Version: 1.0
References: <CANH4o6OpsvT99AeJ2uTcqyajWQHmffYJqV=RR4HBxoFaveR7sQ@mail.gmail.com>
In-Reply-To: <CANH4o6OpsvT99AeJ2uTcqyajWQHmffYJqV=RR4HBxoFaveR7sQ@mail.gmail.com>
Date: Fri, 18 Aug 2023 16:00:10 -0600
Message-ID: <CAJ1FpuOxqdMPkGNVWubS9wzN9TRCTF=evXZ_ue3cvSy-40xgKQ@mail.gmail.com>
Subject: Re: Test for Windows Administrator permissions from Cygwin
 terminal|script?
To: cygwin@cygwin.com
X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL,
 HK_RANDOM_ENVFROM, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS,
 TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Doug Henderson via Cygwin <cygwin@cygwin.com>
Reply-To: Doug Henderson <djndnbvg@gmail.com>
Content-Type: text/plain; charset="utf-8"
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 37IM15l6014333

On Thu, Aug 17, 2023 at 8:02 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.

I use this bash function:

# isadmin - is shell a regular user or admin user
function isadmin()
{
    $(cygpath -u 'C:\Windows\System32\net.exe') session > /dev/null 2>&1
    if [ $? -eq 0 ]; then echo "admin"
    else echo "user"; fi
}

I imagine any other Windows app that needs admin permissions would work.

I use this to change the color of the prompt ($PS1) for the admin user to red.

HTH
Doug

-- 
Doug Henderson, Calgary, Alberta, Canada - from gmail.com

-- 
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

