X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Message-ID: <472C22E0.D19646B3@dessent.net> Date: Sat, 03 Nov 2007 00:27:28 -0700 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: detecting elevation of a process running in bash in vista References: Content-Type: multipart/mixed; boundary="------------FF8296F1E59ED3C9998C2524" X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------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 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 #define _WIN32_WINNT 0x0500 #include 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--