• <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 葉子 閱讀(1453) 評論(0)  編輯 收藏 引用 所屬分類: 網絡安全

            99久久国产综合精品麻豆| 久久久久久久综合日本| 亚洲人成伊人成综合网久久久| 久久精品国产久精国产一老狼| 久久亚洲精品成人av无码网站| 久久免费高清视频| 日本加勒比久久精品| 婷婷伊人久久大香线蕉AV| 99久久国产综合精品网成人影院 | 久久久久人妻精品一区三寸蜜桃 | 岛国搬运www久久| 一个色综合久久| 国产精品一久久香蕉国产线看观看 | 久久99国产精品久久99小说 | 99久久国产热无码精品免费久久久久| 99久久国产综合精品成人影院| 久久精品国产AV一区二区三区| 精品久久久无码中文字幕| 久久国产色AV免费观看| 日产精品久久久久久久| 久久精品国产国产精品四凭 | 日本精品久久久中文字幕| 色欲综合久久躁天天躁蜜桃| 久久亚洲高清综合| 国内精品久久久久久麻豆| 久久狠狠高潮亚洲精品| 性欧美丰满熟妇XXXX性久久久| 一本一道久久a久久精品综合| 99久久国产主播综合精品| 国产精品久久久福利| 久久夜色精品国产噜噜噜亚洲AV| 亚洲国产日韩综合久久精品| 久久国产香蕉视频| 66精品综合久久久久久久| 国产成人久久激情91| 91精品国产乱码久久久久久| 久久av无码专区亚洲av桃花岛| 无码专区久久综合久中文字幕| 婷婷伊人久久大香线蕉AV | 1000部精品久久久久久久久| 欧美喷潮久久久XXXXx|