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

            久久九九久精品国产免费直播| 色天使久久综合网天天| 99精品久久精品| 国产午夜福利精品久久2021| 青青草原1769久久免费播放| 亚洲乱码日产精品a级毛片久久 | 蜜桃麻豆WWW久久囤产精品| 国内精品伊人久久久久777| 久久久久人妻一区二区三区vr| 亚洲精品午夜国产VA久久成人| 久久精品成人免费看| 久久综合精品国产一区二区三区 | 久久免费线看线看| 国内精品伊人久久久久妇| 久久国产精品99精品国产| 久久亚洲国产精品123区| 香蕉久久夜色精品升级完成| 久久国产三级无码一区二区| 亚洲精品乱码久久久久久按摩| 国产精品日韩深夜福利久久| 亚洲欧美成人综合久久久| 久久久99精品成人片中文字幕 | 久久人妻少妇嫩草AV无码蜜桃| 欧美黑人激情性久久| 久久久国产精华液| 久久水蜜桃亚洲av无码精品麻豆| 久久97久久97精品免视看秋霞 | 99久久综合狠狠综合久久| 无码任你躁久久久久久久| 亚洲国产精品久久66| 三上悠亚久久精品| 日本精品久久久久影院日本| 99久久精品国产高清一区二区| 亚洲中文久久精品无码| 精品水蜜桃久久久久久久| 国产精品成人99久久久久| .精品久久久麻豆国产精品| 亚洲级αV无码毛片久久精品| 老司机午夜网站国内精品久久久久久久久| 久久噜噜电影你懂的| 91精品观看91久久久久久|