SOL9 2.0 Class: ProcessUser

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * ProcessUser.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/09/12

#pragma once
#include <sol/Object.h>
#include <sol/String.h>
#include <sol/Arg.h>
#include <sol/AccountSid.h>

#include <psapi.h>
#include <sddl.h>

namespace SOL {

class ProcessUser :public Object {

/*
typedef struct _TOKEN_USER {
  SID_AND_ATTRIBUTES User;
}TOKEN_USER, *PTOKEN_USER;

typedef struct _SID_AND_ATTRIBUTES {
  PSID  Sid;
  DWORD Attributes;
}SID_AND_ATTRIBUTES, *PSID_AND_ATTRIBUTES;

*/

private:
    PTOKEN_USER pToken;

public:
    ProcessUser()
        :pToken(NULL)
    {

    }

public:
    ~ProcessUser()
    {
        clear();
    }

private:
    void clear()
    {
        if (pToken) {
            delete [] (char*)pToken;
            pToken = NULL;
        }
    }

public:
    bool getInformation(HANDLE hToken) 
    {
        bool rc = false;

        clear();
        DWORD dwSize = 0;

        GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenUser, NULL, dwSize, &dwSize);
            
        pToken = (TOKEN_USER*)new char[dwSize];

        if (GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenUser, pToken, dwSize, &dwSize)) {
            rc = true;        
        }
        return rc;
    }


public:
    void display()
    {
        if (pToken) {
            AccountSid accountSid;
            String user;
            String domain;
            String type;
            if (accountSid.lookup(pToken->User.Sid, user, domain, type)) {
                _tprintf(_T("ProcessUser Domain: %s\n"), (const TCHAR*)domain);
                _tprintf(_T("ProcessUser User: %s\n"), (const TCHAR*)user);
                _tprintf(_T("ProcessUser Type: %s\n"), (const TCHAR*)type);

            }
        }
    }

};

}

Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.