/[winpt]/trunk/Src/wptW32API.cpp
ViewVC logotype

Diff of /trunk/Src/wptW32API.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 205 by twoaday, Thu Apr 27 12:46:03 2006 UTC revision 208 by twoaday, Mon May 1 12:22:18 2006 UTC
# Line 634  GetDlgItemText_utf8 (HWND dlg, int id, c Line 634  GetDlgItemText_utf8 (HWND dlg, int id, c
634  }  }
635    
636    
637  struct reminder_hd_s {  /* Return TRUE if the current user has admin privileges. */
638      int msecs;  BOOL
639      HWND dlg;  user_is_admin (void)
     HANDLE hd;  
 };  
   
   
 static DWORD CALLBACK  
 foreground_reminder_thread (void *c)  
640  {  {
641      struct reminder_hd_s *ctx = (struct reminder_hd_s *)c;      SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
642      Sleep (ctx->msecs);      HANDLE hd;
643      SetForegroundWindow (ctx->dlg);      TOKEN_GROUPS  *ptg = NULL;
644      CloseHandle (ctx->hd);      DWORD ngtoken;
645      delete ctx;      DWORD i;
646      ExitThread (0);      BOOL admin = FALSE;
647      return 0;      PSID psid = 0;
648  }  
649        if (GetVersion () & 0x80000000) /* Win9X */
650  /* Try to force the window @dlg to the foreground.          return TRUE;
651     On NT5 or later this will not work if the user  
652     is working in another window (console for example). */      if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, FALSE, &hd) &&
653  void          !OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hd))
654  force_foreground_window (HWND dlg, int msecs)          return FALSE;
655  {      
656      struct reminder_hd_s *hd;      if (!GetTokenInformation (hd, TokenGroups, NULL, 0, &ngtoken) &&
657      DWORD tid;          GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
658            ptg = (TOKEN_GROUPS*)GlobalAlloc (GPTR, ngtoken);
659            if (!ptg)
660                return FALSE;
661    
662            if (!GetTokenInformation (hd, TokenGroups,
663                                      ptg, ngtoken, &ngtoken)) {
664                GlobalFree (ptg);
665                return FALSE;
666            }
667            AllocateAndInitializeSid (&SystemSidAuthority,
668                                      2, SECURITY_BUILTIN_DOMAIN_RID,
669                                      DOMAIN_ALIAS_RID_ADMINS,
670                                      0, 0, 0, 0, 0, 0,
671                                      &psid);
672            for (i = 0; i < ptg->GroupCount; i++) {
673                if (EqualSid (ptg->Groups[i].Sid, psid)) {
674                    admin = TRUE;
675                    break;
676                }
677            }
678            FreeSid (psid);
679            GlobalFree (ptg);
680        }
681    
682      hd = new reminder_hd_s;      CloseHandle (hd);
683      hd->dlg = dlg;      return admin;
     hd->msecs = msecs;  
     hd->hd = CreateThread (NULL, 0, foreground_reminder_thread,  
                            hd, NULL, &tid);  
684  }  }

Legend:
Removed from v.205  
changed lines
  Added in v.208

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26