Mail Archives: cygwin/2007/11/03/02:28:07
--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Kurt Franke wrote:
> does anyone found a methode to detect if a bash process
> is running so-called "elevated" with cygwin on windows vista ?
> it would be a nice feature setting the prompt to a value
> reflecting this like done when running as root under an unix os.
> or to modify the windows title to reflect the fact that
> the shell is running with special privileges.
You can use something like the attached program. It will simply return
an exit status code so that in your shell startup you can e.g.:
if isadmin; then
title="[Admin]"
else
title=""
fi
PS1='\[\e]0;$title\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
Note that w32api currently lacks the CheckTokenMembership() prototype so
you'll need to apply
<http://sourceforge.net/tracker/index.php?func=detail&aid=1825044&group_id=2435&atid=302435>
first in order to build this.
Brian
--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii;
name="isadmin.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="isadmin.c"
#include <stdio.h>
#define _WIN32_WINNT 0x0500
#include <windows.h>
int main (int argc, char **argv)
{
SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
PSID AdministratorsGroup;
BOOL isAdmin;
if (AllocateAndInitializeSid (&NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0, &AdministratorsGroup) == 0 ||
CheckTokenMembership (NULL, AdministratorsGroup, &isAdmin) == 0)
{
printf ("failed with win32 error %lu\n", GetLastError ());
exit (2);
}
FreeSid (AdministratorsGroup);
exit (!isAdmin);
}
--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
--------------FF8296F1E59ED3C9998C2524--
- Raw text -