delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/02/05/04:45:17

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:mime-version
:content-type:content-transfer-encoding; q=dns; s=default; b=BE+
/NmpprUbrDzViD2rDAj3MTZdnKn5DolizmWC9t63RFQF7BpEdmG8U8YSJSbsj+Ne
pEpBN9HTnaGE5g4o2vXhE4Z1HQt6CsQvSNpqurxuGYP4X2rJ6lBgNGlnR6QTG+Iq
wmtCh03pqKM1mEqaTMc8QT/EgS58ApBYRA+E0gXs=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:to:from:subject:date:message-id:mime-version
:content-type:content-transfer-encoding; s=default; bh=1QnZNyh15
eT7iEE3ft4e8WcL8JY=; b=DdeaFwQFiiPgix56AgqWRbAV+as+uCJo3D9pGyt4E
IUXrFqUSc8YsPIlWDChPqcVf/DS1TBdKvRmkSrZUWutEOAWFkX+dg8Djw7is3sGj
GoAje3g4cxirzloFfNLDI1SdkU3cJM/RrkJ6dmEQEgo/KcqzW8U5HkLpaxOT2fwS
2U=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2
X-HELO: plane.gmane.org
To: cygwin AT cygwin DOT com
From: Andrew Schulman <schulman DOT andrew AT epa DOT gov>
Subject: how to determine if a shell is running as Administrator?
Date: Thu, 05 Feb 2015 04:43:09 -0500
Lines: 39
Message-ID: <slc6da9aq8g9e7h0aegafhfa86eahfd53p@4ax.com>
Mime-Version: 1.0
X-Archive: encrypt
X-IsSubscribed: yes

What's a reliable and efficient way to determine programmatically if the shell
that's running has elevated privileges?

Or if you prefer, how can I tell if the shell was started with "Run as
administrator"?

I'm looking for a solution that's reliable across installations and OS versions.
I want it also to be fairly fast, so it can be used for example in setting shell
prompts.

There's a SuperUser thread[1] that talks about this.  None of the solutions
seems completely satisfactory:

1. Run a command that only an Administrator can run, and check the return
status.  But which one?  Suggestions are:

  a. at. But at may not be on the $PATH, or supported.

  b. touch /cygdrive/c/Users/.x , or some other protected path.  But which paths
are protected is installation-dependent (as is the /cygdrive prefix).

  c. editrights -l.  On my host my unprivileged account can't even run this, so
I get a return status of 1.  In a privileged shell I get 0 or 2.  Is that
reliable?

  d. ??

2. Parse the output of groups or id -G.  I can't find any reliable way to do
this.  For example on my host, when I start a shell with "Run as administrator",
the new group I get isn't 544 (Administrators).  It's 114 (Local account and
member of Administrators group).  Is that at all portable or reliable?

What other ways are there?

Thanks,
Andrew

[1]
http://superuser.com/questions/660191/how-to-check-if-cygwin-mintty-bash-is-run-as-administrator


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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019