Click here to Skip to main content
15,905,004 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalactivex property initialisation Pin
Debs24-Nov-02 23:58
Debs24-Nov-02 23:58 
GeneralRe: activex property initialisation Pin
Heath Stewart25-Nov-02 2:38
protectorHeath Stewart25-Nov-02 2:38 
QuestionOne resource in more than one project? Pin
Anonymous24-Nov-02 22:38
Anonymous24-Nov-02 22:38 
AnswerRe: One resource in more than one project? Pin
Stephane Rodriguez.25-Nov-02 0:05
Stephane Rodriguez.25-Nov-02 0:05 
AnswerRe: One resource in more than one project? Pin
dima_t25-Nov-02 0:39
dima_t25-Nov-02 0:39 
AnswerRe: One resource in more than one project? Pin
KarstenK25-Nov-02 3:06
mveKarstenK25-Nov-02 3:06 
QuestionHow to write a Code Generator similar to Visual Studio Pin
aninddroy24-Nov-02 22:34
aninddroy24-Nov-02 22:34 
AnswerRe: How to write a Code Generator similar to Visual Studio Pin
Simon.W25-Nov-02 1:31
Simon.W25-Nov-02 1:31 
GeneralClosing already running instance Pin
suresh_sathya24-Nov-02 22:32
suresh_sathya24-Nov-02 22:32 
GeneralRe: Closing already running instance Pin
Roman Fadeyev24-Nov-02 23:33
Roman Fadeyev24-Nov-02 23:33 
GeneralRe: Closing already running instance Pin
suresh_sathya25-Nov-02 0:50
suresh_sathya25-Nov-02 0:50 
QuestionHow to use a DirectShow sample filter ? Pin
manio24-Nov-02 21:00
manio24-Nov-02 21:00 
AnswerRe: How to use a DirectShow sample filter ? Pin
Stephane Rodriguez.25-Nov-02 0:07
Stephane Rodriguez.25-Nov-02 0:07 
GeneralRe: How to use a DirectShow sample filter ? Pin
manio25-Nov-02 15:23
manio25-Nov-02 15:23 
GeneralRe: How to use a DirectShow sample filter ? Pin
Stephane Rodriguez.26-Nov-02 6:50
Stephane Rodriguez.26-Nov-02 6:50 
GeneralPorting from a NT to a '98 Pin
BlackRider24-Nov-02 20:43
BlackRider24-Nov-02 20:43 
GeneralRe: Porting from a NT to a '98 Pin
KarstenK24-Nov-02 21:12
mveKarstenK24-Nov-02 21:12 
GeneralNot a solution Pin
BlackRider24-Nov-02 21:29
BlackRider24-Nov-02 21:29 
GeneralRe: Not a solution Pin
KarstenK24-Nov-02 21:43
mveKarstenK24-Nov-02 21:43 
GeneralRe: Not a solution Pin
Daniel Turini24-Nov-02 22:57
Daniel Turini24-Nov-02 22:57 
Generaldetect if user has admin privilege Pin
devvvy24-Nov-02 20:24
devvvy24-Nov-02 20:24 
GeneralRe: detect if user has admin privilege Pin
Daniel Turini24-Nov-02 21:09
Daniel Turini24-Nov-02 21:09 
static inline BOOL IsAdmin(void) {
        
        HANDLE hToken;
        DWORD  dwStatus;
        DWORD  dwAccessMask;
        DWORD  dwAccessDesired;
        DWORD  dwACLSize;
        DWORD  dwStructureSize = sizeof(PRIVILEGE_SET);
        PACL   pACL            = NULL;
        PSID   psidAdmin       = NULL;
        BOOL   bReturn         = FALSE;
        
        PRIVILEGE_SET   ps;
        GENERIC_MAPPING GenericMapping;
        
        PSECURITY_DESCRIPTOR     psdAdmin           = NULL;
        SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
        
        __try {
                
                ImpersonateSelf(SecurityImpersonation);
                
                if (!OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, 
            &hToken)) {
                        
                        if (GetLastError() != ERROR_NO_TOKEN)
                                __leave;
                        
                        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, 
                                &hToken))
                                __leave;
                }
                
                if (!AllocateAndInitializeSid(&SystemSidAuthority, 2, 
            SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
            0, 0, 0, 0, 0, 0, &psidAdmin))
                        __leave;
                
                psdAdmin = LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
                if (psdAdmin == NULL)
                        __leave;
                
                if (!InitializeSecurityDescriptor(psdAdmin,
            SECURITY_DESCRIPTOR_REVISION))
                        __leave;
                
                dwACLSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) +
            GetLengthSid(psidAdmin) - sizeof(DWORD);
                
                pACL = (PACL)LocalAlloc(LPTR, dwACLSize);
                if (pACL == NULL)
                        __leave;
                
                if (!InitializeAcl(pACL, dwACLSize, ACL_REVISION2))
                        __leave;
                
                dwAccessMask= ACCESS_READ | ACCESS_WRITE;
                
                if (!AddAccessAllowedAce(pACL, ACL_REVISION2,
            dwAccessMask, psidAdmin))
                        __leave;
                
                if (!SetSecurityDescriptorDacl(psdAdmin, TRUE, pACL, FALSE))
                        __leave;
                
                SetSecurityDescriptorGroup(psdAdmin, psidAdmin, FALSE);
                SetSecurityDescriptorOwner(psdAdmin, psidAdmin, FALSE);
                
                if (!IsValidSecurityDescriptor(psdAdmin))
                        __leave;
                
                dwAccessDesired = ACCESS_READ;
                
                GenericMapping.GenericRead    = ACCESS_READ;
                GenericMapping.GenericWrite   = ACCESS_WRITE;
                GenericMapping.GenericExecute = 0;
                GenericMapping.GenericAll     = ACCESS_READ | ACCESS_WRITE;
                
                if (!AccessCheck(psdAdmin, hToken, dwAccessDesired, 
            &GenericMapping, &ps, &dwStructureSize, &dwStatus, 
            &bReturn)) {
                        printf("AccessCheck() failed with error %lu\n", GetLastError());
                        __leave;
                }
                
                RevertToSelf();
                
        } __finally {
                
                // Cleanup 
                if (pACL) LocalFree(pACL);
                if (psdAdmin) LocalFree(psdAdmin);  
                if (psidAdmin) FreeSid(psidAdmin);
        }
        
        return bReturn;
}


This is what I use to check for domain Admins. I found it on MSDN somewhere I don't recall and adapted for my specific use. You can use it as a starting point.


My latest article:
SQL Server DO's and DONT's[^]
GeneralRe: detect if user has admin privilege Pin
devvvy24-Nov-02 21:47
devvvy24-Nov-02 21:47 
GeneralRe: detect if user has admin privilege Pin
Daniel Turini24-Nov-02 22:06
Daniel Turini24-Nov-02 22:06 
GeneralCreating a window in an ATL without MFC Pin
Jerome Conus24-Nov-02 20:19
Jerome Conus24-Nov-02 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.