Click here to Skip to main content
13,147,344 members (28,265 online)
Click here to Skip to main content

Stats

81.8K views
2K downloads
172 bookmarked
Posted 12 Aug 2008

ProSysLib: Dissecting the Process

, 22 Nov 2010
Access detailed information about the current process the easiest way.
ProcessInfo.exe
ProSysLib.dll
Interop.ProSysLib.dll
Interop.ProSysLib.dll
ProcessInfo.exe
ProSysLib.dll
PSL64v0.9.dll
Interop.ProSysLib.dll
ProcessInfo.exe
PSL32v0.9.dll
ProSysLib_v0.9
Bin
PSL32v0.9.dll
PSL64v0.9.dll
Help
Samples
C#2008
ProcessInfo
Properties
ProcessViewer
Properties
VB6
CPUInfo.exe
CPUInfo.frm
CPUInfo.frx
CPUInfo.vbp
CPUInfo.vbw
VC2008
Deployment
Src
mssccprj.scc
ProSysLib.def
ProSysLib.rgs
ProSysLib.vcproj.vspscc
ProSysLib.vssscc
PSLSystem.rgs
PSLv0.5Setup.exe
PSLv0.7Setup.exe
// PSLPrivileges.cpp : Implementation of CPSLPrivileges

#include "stdafx.h"
#include "PSLPrivileges.h"


CPSLPrivileges::CPSLPrivileges()
{
}

HRESULT CPSLPrivileges::OnIndexOutOfRange()
{
	return MakeException(exIndexOutOfRange);
}

HRESULT CPSLPrivileges::FinalConstruct()
{
	PSL_BEGIN

	InternalUpdate();
	
	PSL_END
}

void CPSLPrivileges::FinalRelease()
{
}

void CPSLPrivileges::InternalUpdate()
{
	CCritSecLock cs(m_csCollection);

	m_coll.clear(); // Releases interfaces and clears the collection;
					// NOTE: .NET clients catch up interfaces, so takes
					// about 30 seconds before they are garbaged by .NET;

	HANDLE hToken = NULL;
	if(::OpenProcessToken(::GetCurrentProcess(), TOKEN_READ, &hToken))
	{
		DWORD dwLength = 0;
		::GetTokenInformation(hToken, TokenPrivileges, NULL, 0, &dwLength);
		LPBYTE pBuffer = new BYTE[dwLength];
		if(::GetTokenInformation(hToken, TokenPrivileges, pBuffer, dwLength, &dwLength))
		{
			TOKEN_PRIVILEGES * pPrivileges = (TOKEN_PRIVILEGES*)(LPVOID)pBuffer;
			LUID_AND_ATTRIBUTES * Privileges = pPrivileges->Privileges;
			DWORD dwCount = pPrivileges->PrivilegeCount;
			TCHAR PrivilegeName[64];
			for(DWORD i = 0;i < dwCount;i ++)
			{
				DWORD dwLength = 64;
				if(::LookupPrivilegeName(NULL, &Privileges[i].Luid, PrivilegeName, &dwLength))
				{
					CComObject<CPSLPrivilege> * pPrivilege = NULL;
					if(CComObject<CPSLPrivilege>::CreateInstance(&pPrivilege) == S_OK)
					{
						pPrivilege->Initialize(Privileges[i], PrivilegeName);
						// NOTE: Here the interface is also gets AddRef;
						m_coll.push_back(CComPtr<IPSLPrivilege>(pPrivilege));
					}
				}		
			}			
		}
		delete []pBuffer;
		::CloseHandle(hToken);
	}
}

////////////////////////////////////////////////////////////////////////
// Interface Implementation;
////////////////////////////////////////////////////////////////////////

STDMETHODIMP CPSLPrivileges::Update()
{
	PSL_BEGIN

	InternalUpdate();

	PSL_END
}

STDMETHODIMP CPSLPrivileges::Find(BSTR PrivilegeName, IPSLPrivilege ** ppValue)
{
	PSL_BEGIN

	*ppValue = NULL;
	_bstr_t sPrivilegeName(PrivilegeName);
	CCritSecLock cs(m_csCollection);

	for(PrivilegesType::iterator i = m_coll.begin();i != m_coll.end();i ++)
	{
		BSTR sName = NULL;
		if(i->m_T->get_Name(&sName) == S_OK)
		{
			_bstr_t s(sName);
			if(!::_tcsicmp(s, sPrivilegeName)) // Doing case-insensitive comparison;
			{
				IPSLPrivilege * pPrivilege = i->m_T;
				pPrivilege->AddRef();
				*ppValue = pPrivilege;
				break;
			}
		}	
	}

	PSL_END
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Vitaly Tomilov
Software Developer (Senior) Sibedge IT
Ireland Ireland
My online CV: cv.vitalytomilov.com

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid