This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: how to determine if a shell is running as Administrator?
- From: dboyd2 at mmm dot com (J. David Boyd)
- To: cygwin at cygwin dot com
- Date: Thu, 05 Feb 2015 09:18:03 -0500
- Subject: Re: how to determine if a shell is running as Administrator?
- Authentication-results: sourceware.org; auth=none
- References: <slc6da9aq8g9e7h0aegafhfa86eahfd53p at 4ax dot com> <20150205100349 dot GS2635 at calimero dot vinschen dot de>
Corinna Vinschen <corinna-cygwin@cygwin.com> writes:
> On Feb 5 04:43, Andrew Schulman wrote:
>> 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"?
>
> id -G | grep -qE '\<544\>' && echo admin || echo luser
>
>> 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?
>
> Huh? There is no such group in Windows. Where does it come from?
> This should always work even with old /etc/group files:
>
> id -G | grep -qE '\<544\>|\<0\>' && echo admin || echo luser
>
>
> Corinna
This doesn't seem to tell me if my shell has been started with 'Run As
Administrator', it just tells me if my user is contained in the Administrator
group.
I can start a cygwin shell, and start a cygwin shell with run as admin, and I
get the same results from the above command.
Dave
--
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