• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            elva

            判斷當前用戶是否為系統管理員

            #include <windows.h>
            #include <stdio.h>
            #include <lm.h>
            #pragma hdrstop

            #pragma comment( lib, "netapi32.lib" )

            // My thanks to Jerry Coffin (jcoffin@taeus.com)
            // for this much simpler method.
            bool jerry_coffin_method()
            {
                bool result;
                DWORD rc;
                wchar_t user_name[256];
                USER_INFO_1 *info;
                DWORD size = sizeof( user_name );

                GetUserNameW( user_name, &size);

                rc = NetUserGetInfo( NULL, user_name, 1, (byte **) &info );
                if ( rc != NERR_Success )
                    return false;

                result = info->usri1_priv == USER_PRIV_ADMIN;

                NetApiBufferFree( info );
                return result;
            }



            bool look_at_token_method()
            {
                int found;
                DWORD i, l;
                HANDLE hTok;
                PSID pAdminSid;
                SID_IDENTIFIER_AUTHORITY ntAuth = SECURITY_NT_AUTHORITY;

                byte rawGroupList[4096];
                TOKEN_GROUPS& groupList = *( (TOKEN_GROUPS *) rawGroupList );

                if ( ! OpenThreadToken( GetCurrentThread(), TOKEN_QUERY, FALSE, &hTok ) )
                {
                    printf( "Cannot open thread token, trying process token [%lu].n",
                        GetLastError() );
                    if ( ! OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hTok ) )
                    {
                        printf( "Cannot open process token, quitting [%lu].n",
                            GetLastError() );
                        return 1;
                    }
                }

                // normally, I should get the size of the group list first, but ...
                l = sizeof rawGroupList;
                if ( ! GetTokenInformation( hTok, TokenGroups, &groupList, l, &l ) )
                {
                    printf( "Cannot get group list from token [%lu].n",
                        GetLastError() );
                    return 1;
                }

                // here, we cobble up a SID for the Administrators group, to compare to.
                if ( ! AllocateAndInitializeSid( &ntAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
                    DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pAdminSid ) )
                {
                    printf( "Cannot create SID for Administrators [%lu].n",
                        GetLastError() );
                    return 1;
                }

                // now, loop through groups in token and compare
                found = 0;
                for ( i = 0; i < groupList.GroupCount; ++ i )
                {
                    if ( EqualSid( pAdminSid, groupList.Groups[i].Sid ) )
                    {
                        found = 1;
                        break;
                    }
                }

                FreeSid( pAdminSid );
                CloseHandle( hTok );
                return !!found;
            }

            int main()
            {
                bool j, l;

                j = jerry_coffin_method();
                l = look_at_token_method();

                printf( "NetUserGetInfo(): The current user is %san Administrator.n",
                    j? "": "not " );
                printf( "Process token: The current user is %sa member of the Administrators group.n",
                    l? "": "not " );

                return 0;
            }

            posted on 2007-05-14 00:56 葉子 閱讀(1465) 評論(0)  編輯 收藏 引用 所屬分類: 網絡安全

            婷婷久久综合九色综合98| 国产精品亚洲美女久久久| 无码八A片人妻少妇久久| 久久精品国产亚洲7777| 久久久久亚洲av综合波多野结衣| 久久亚洲sm情趣捆绑调教 | 狠狠色丁香久久婷婷综合_中| 亚洲国产成人久久综合一区77| 久久精品国产免费观看 | 国产精品久久久久久久久鸭| 中文字幕亚洲综合久久2| 久久无码国产| 久久青青草原精品国产| 久久精品成人免费观看97| 久久WWW免费人成一看片| av无码久久久久不卡免费网站| 久久久91精品国产一区二区三区| 久久亚洲视频| 久久香蕉国产线看观看精品yw| 女同久久| 中文字幕成人精品久久不卡| 看久久久久久a级毛片| 色诱久久av| 色综合合久久天天综合绕视看| 久久人人爽人人爽人人爽| 久久精品无码一区二区日韩AV| 欧美喷潮久久久XXXXx| 99久久精品免费看国产一区二区三区 | 无码精品久久久久久人妻中字| 久久久精品午夜免费不卡| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 国内精品人妻无码久久久影院 | 日本欧美久久久久免费播放网 | 久久精品国产亚洲网站| 人人狠狠综合久久88成人| 一本久久综合亚洲鲁鲁五月天| 国产精品狼人久久久久影院| 香港aa三级久久三级| 99久久无码一区人妻a黑| 国内精品久久久久影院日本| 欧美大香线蕉线伊人久久|