• <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)  編輯 收藏 引用 所屬分類: 網絡安全

            香蕉久久夜色精品国产2020 | 嫩草影院久久99| 久久噜噜电影你懂的| 18岁日韩内射颜射午夜久久成人| 久久涩综合| 久久99中文字幕久久| 久久久久亚洲?V成人无码| 99精品国产99久久久久久97| 99久久精品免费国产大片| 性欧美丰满熟妇XXXX性久久久 | AV无码久久久久不卡蜜桃 | 久久久亚洲欧洲日产国码aⅴ| 久久久国产精品网站| 亚洲午夜久久久久妓女影院| 久久婷婷色综合一区二区| 久久99精品国产麻豆宅宅| 香蕉久久av一区二区三区| 日韩影院久久| 久久黄视频| 狠狠色综合网站久久久久久久| 久久综合88熟人妻| 亚洲国产精品一区二区久久hs| 久久久久噜噜噜亚洲熟女综合| 色综合久久最新中文字幕| 久久成人国产精品免费软件| 亚洲国产成人久久精品影视| 国产成年无码久久久免费| 久久笫一福利免费导航 | 亚洲国产香蕉人人爽成AV片久久| 久久国产精品久久| 精品国产乱码久久久久久郑州公司 | 美女写真久久影院| 国产精品久久久久久久久免费| 久久天天躁狠狠躁夜夜网站| 色偷偷久久一区二区三区| 久久天天躁狠狠躁夜夜网站| 久久午夜羞羞影院免费观看| 99久久国语露脸精品国产| 伊人丁香狠狠色综合久久| 国产精品激情综合久久| 狠狠人妻久久久久久综合蜜桃 |