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

            久久男人AV资源网站| 韩国免费A级毛片久久| 久久九九久精品国产| 久久天天躁狠狠躁夜夜2020一 | 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久只有这精品99| 伊人久久综在合线亚洲2019| 亚洲愉拍99热成人精品热久久 | 亚洲中文久久精品无码ww16| 国产精品久久久天天影视| 婷婷综合久久中文字幕蜜桃三电影 | 久久精品国产欧美日韩| 久久久无码人妻精品无码| 国产精品久久婷婷六月丁香| 久久久久国产一区二区| 亚洲欧美日韩中文久久 | 欧洲精品久久久av无码电影| 国产亚洲美女精品久久久| 99久久免费只有精品国产| 无码AV波多野结衣久久| 亚洲欧美日韩久久精品| 久久笫一福利免费导航| 久久久青草青青亚洲国产免观| 狠狠色丁香久久综合婷婷| 精品999久久久久久中文字幕| 久久国产精品无| 久久亚洲国产成人影院网站| 亚洲乱亚洲乱淫久久| 99久久无码一区人妻a黑| 久久久久国产精品人妻| 久久影院久久香蕉国产线看观看| 伊人久久综在合线亚洲2019| 国产成年无码久久久久毛片| 97超级碰碰碰久久久久| 久久久久久毛片免费播放| 亚洲av成人无码久久精品| 无码人妻久久一区二区三区蜜桃 | 久久成人小视频| 一级A毛片免费观看久久精品| 亚洲欧美久久久久9999| 久久强奷乱码老熟女网站|