/*
* ProcessOwner.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 ProcessOwner :public Object {
/*
typedef struct _TOKEN_OWNER {
PSID Owner;
}TOKEN_OWNER, *PTOKEN_OWNER;
*/
private:
PTOKEN_OWNER pToken;
public:
ProcessOwner()
:pToken(NULL)
{
}
public:
~ProcessOwner()
{
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)TokenOwner, NULL, dwSize, &dwSize);
pToken = (TOKEN_OWNER*)new char[dwSize];
if (GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)TokenOwner, pToken, dwSize, &dwSize) ) {
rc = true;
}
return rc;
}
public:
void display()
{
if (pToken) {
AccountSid accountSid;
String user;
String domain;
String type;
if (accountSid.lookup(pToken->Owner, user, domain, type)) {
_tprintf(_T("ProcessOwner Domain: %s\n"), (const TCHAR*)domain);
_tprintf(_T("ProcessOwner User: %s\n"), (const TCHAR*)user);
_tprintf(_T("ProcessOwner Type: %s\n"), (const TCHAR*)type);
}
}
}
};
}
|