This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: how to determine if a shell is running as Administrator?


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

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpR2K_gJGpmt.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]