Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在vc+中的mfc中,在msdn中以管理员模式(以管理员身份运行)打开应用程序时,查找登录用户是否为管理员+;_C++_Visual C++_Mfc_Msdn - Fatal编程技术网

C++ 在vc+中的mfc中,在msdn中以管理员模式(以管理员身份运行)打开应用程序时,查找登录用户是否为管理员+;

C++ 在vc+中的mfc中,在msdn中以管理员模式(以管理员身份运行)打开应用程序时,查找登录用户是否为管理员+;,c++,visual-c++,mfc,msdn,C++,Visual C++,Mfc,Msdn,我使用以下代码来查找登录的用户是否是管理员,即使应用程序在vc++中mfc中的msdn中以管理员模式打开(以管理员身份运行) bool CC_AdministratorDlg::IsAdministrator() { bool bIsAdmin = false; try { // Open the access token of the current process. ATL::CAccessToken aToken;

我使用以下代码来查找登录的用户是否是管理员,即使应用程序在vc++中mfc中的msdn中以管理员模式打开(以管理员身份运行)

bool  CC_AdministratorDlg::IsAdministrator()
{
    bool bIsAdmin = false;


    try
    {
        // Open the access token of the current process.
        ATL::CAccessToken aToken;
        if (!aToken.GetProcessToken(TOKEN_QUERY))
        {
            throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
                ::GetLastError());
        }


        // Query for the access token's group information.
        ATL::CTokenGroups groups;
        if (!aToken.GetGroups(&groups))
        {
            throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
                ::GetLastError());
        }

        // Iterate through the access token's groups
        // looking for a match against the builtin admins group.
        ATL::CSid::CSidArray groupSids;
        ATL::CAtlArray<DWORD> groupAttribs;
        groups.GetSidsAndAttributes(&groupSids, &groupAttribs);
        for (UINT i = 0; !bIsAdmin && i < groupSids.GetCount(); ++i)
        {
            bIsAdmin = groupSids.GetAt(i) == ATL::Sids::Admins();
        }
        if(bIsAdmin== false)
        {
            MessageBox(_T("Switch to admin mode"),_T("information"),NULL);
        }


    }
    catch (HRESULT hr)
    {

    }

    return bIsAdmin;
}
bool CC_AdministratorDlg::IsAdministrator()
{
bool-bIsAdmin=false;
尝试
{
//打开当前进程的访问令牌。
ATL::CAccessToken aToken;
if(!aToken.GetProcessToken(TOKEN\u查询))
{
抛出MAKE\u SCODE(严重性错误、设备WIN32、,
::GetLastError());
}
//查询访问令牌的组信息。
ATL::CTokenGroup组;
如果(!aToken.GetGroups(&groups))
{
抛出MAKE\u SCODE(严重性错误、设备WIN32、,
::GetLastError());
}
//迭代访问令牌的组
//正在寻找与内置管理员组的匹配。
ATL::CSid::CSidArray组SID;
ATL::CAtlArray groupAttribs;
groups.GetSidsAndAttributes(&groupSids,&groupAttribs);
对于(UINT i=0;!bIsAdmin&&i

它在正常模式下打开时工作正常。但当我以管理员身份打开run时,在这种情况下,它总是返回admin,即使用户不是admin。是否有办法在vc++中的mfc中的msdn中以管理员模式(以管理员身份运行)打开应用程序,但仍能找到登录的用户是否为admin。

您期待什么?该程序实际上是通过管理登录运行的,尽管它是从不同的登录启动的。@Blacktempel::“IsUserAnAdmin可在“要求”部分中指定的操作系统中使用。它可能在后续版本中被更改或不可用。[…]客户端支持结束:Windows Vista”…我认为答案取决于你所说的“用户就是管理员”的实际含义。可以这样细化您的问题吗:您想知道,当前在本地登录的用户(与运行您的应用程序的用户不同)是否是本地管理员组的成员?您能告诉我们有关您想对该“真实”用户做什么以及为什么需要它的更多信息吗?您期望得到什么?该程序实际上是通过管理登录运行的,尽管它是从不同的登录启动的。@Blacktempel::“IsUserAnAdmin可在“要求”部分中指定的操作系统中使用。它可能在后续版本中被更改或不可用。[…]客户端支持结束:Windows Vista”…我认为答案取决于你所说的“用户就是管理员”的实际含义。可以这样细化您的问题吗:您想知道,当前在本地登录的用户(与运行您的应用程序的用户不同)是否是本地管理员组的成员?您能否告诉我们有关您想对该“真实”用户做什么以及为什么需要它的更多信息?
bool  CC_AdministratorDlg::IsAdministrator()
{
    bool bIsAdmin = false;


    try
    {
        // Open the access token of the current process.
        ATL::CAccessToken aToken;
        if (!aToken.GetProcessToken(TOKEN_QUERY))
        {
            throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
                ::GetLastError());
        }


        // Query for the access token's group information.
        ATL::CTokenGroups groups;
        if (!aToken.GetGroups(&groups))
        {
            throw MAKE_SCODE(SEVERITY_ERROR, FACILITY_WIN32,
                ::GetLastError());
        }

        // Iterate through the access token's groups
        // looking for a match against the builtin admins group.
        ATL::CSid::CSidArray groupSids;
        ATL::CAtlArray<DWORD> groupAttribs;
        groups.GetSidsAndAttributes(&groupSids, &groupAttribs);
        for (UINT i = 0; !bIsAdmin && i < groupSids.GetCount(); ++i)
        {
            bIsAdmin = groupSids.GetAt(i) == ATL::Sids::Admins();
        }
        if(bIsAdmin== false)
        {
            MessageBox(_T("Switch to admin mode"),_T("information"),NULL);
        }


    }
    catch (HRESULT hr)
    {

    }

    return bIsAdmin;
}