⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sidviewer.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
#include <iostream>
#include <strstrea.h>
#include <windows.h>

strstream SidToString(PSID psid)
{
    strstream str;

    // is the sid valid?
    if(!::IsValidSid(psid))
    {
        return str;
    }
    // retrieve identifier authority
    PSID_IDENTIFIER_AUTHORITY pia = 
        ::GetSidIdentifierAuthority(psid);
    // append prefix and revision number
    str << "S-" << SID_REVISION << "-";
    // append identifier authority
    if ( (pia->Value[0] != 0) || (pia->Value[1] != 0) )
    {
        str << (USHORT)pia->Value[0]
                   << (USHORT)pia->Value[1]
                   << (USHORT)pia->Value[2]
                   << (USHORT)pia->Value[3]
                   << (USHORT)pia->Value[4]
                   << (USHORT)pia->Value[5];
    }
    else
    {
        str << ((ULONG)(pia->Value[5]      )   +
                    (ULONG)(pia->Value[4] <<  8)   +
                    (ULONG)(pia->Value[3] << 16)   +
                    (ULONG)(pia->Value[2] << 24)   );
    }
    // retrieve count of sub authorities
    DWORD dw = *::GetSidSubAuthorityCount(psid);
    // append subauthorities
    for (int i=0 ; i < (int)dw ; i++)
    {
        str << "-" << *::GetSidSubAuthority(psid, i);
    }
    return str;
}

using namespace std ;

int main(int, char **)
{

    DWORD dwSize = 0;
    HANDLE hToken;

    // retrieve the current process' access token handle
    if (!::OpenProcessToken( ::GetCurrentProcess(), 
                             TOKEN_QUERY, &hToken ))
    {
        std::cout << "Error ::OpenProcessToken " 
                  << ::GetLastError() << endl;
        return 0;
    }
    // retrieve the size of the token group structure
    if(!::GetTokenInformation(hToken, TokenGroups, NULL, 
                              dwSize, &dwSize))
    {
        DWORD dw = ::GetLastError();
        if( dw != ERROR_INSUFFICIENT_BUFFER )
        {
            std::cout << "Error ::GetTokenInformation " 
                      << dw << endl;
            return 0;
        }
    }
    // allocate the token group structure
    PTOKEN_GROUPS pTokenGroups = (PTOKEN_GROUPS) 
                         ::GlobalAlloc( GPTR, dwSize );
    // retrieve the token group structure
    if(!::GetTokenInformation(hToken, TokenGroups, 
                              pTokenGroups, dwSize, 
                              &dwSize ))
    {
        std::cout << "Error ::GetTokenInformation " 
                  << ::GetLastError() << endl;
    }
    else
    {
        // dump all the group sids
        for(int i=0; i<(int)pTokenGroups->GroupCount; i++)
        {
            std::cout 
            << SidToString(pTokenGroups->Groups[i].Sid).str() 
            << endl;
        }
    }

    // clean up
    if ( pTokenGroups )
    {
        ::GlobalFree( pTokenGroups );
    }
    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -