Click here to Skip to main content
13,054,615 members (58,139 online)
Click here to Skip to main content

Stats

80.2K views
1.9K 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
// PSLPrivilege.cpp : Implementation of CPSLPrivilege

#include "stdafx.h"
#include "PSLPrivilege.h"

#define LUID_TO_QWORD(luid) (((__int64)luid.HighPart) << 32) + luid.LowPart

CPSLPrivilege::CPSLPrivilege()
{
	m_sName = _T("");

	m_bEnabled = false;
	m_bDefault = false;
	m_bRemoved = false;
	m_bUsedForAccess = false;

	m_Luid.HighPart = 0;
	m_Luid.LowPart = 0;
}

CPSLPrivilege::~CPSLPrivilege()
{

}

HRESULT CPSLPrivilege::FinalConstruct()
{
	return S_OK;
}

void CPSLPrivilege::FinalRelease()
{
}

void CPSLPrivilege::Initialize(LUID_AND_ATTRIBUTES & Attributes, LPCTSTR sPrivilegeName)
{
	m_sName = sPrivilegeName;
	m_Luid = Attributes.Luid;
	if(Attributes.Attributes)
	{
		m_bEnabled = (Attributes.Attributes & SE_PRIVILEGE_ENABLED) == SE_PRIVILEGE_ENABLED;
		m_bDefault = (Attributes.Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT) == SE_PRIVILEGE_ENABLED_BY_DEFAULT;
		m_bRemoved = (Attributes.Attributes & SE_PRIVILEGE_REMOVED) == SE_PRIVILEGE_REMOVED;
		m_bUsedForAccess = (Attributes.Attributes & SE_PRIVILEGE_USED_FOR_ACCESS) == SE_PRIVILEGE_USED_FOR_ACCESS;
	}
}

bool CPSLPrivilege::EnablePrivilege(bool bEnable)
{
	TOKEN_PRIVILEGES tp;
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = m_Luid;
	if(bEnable)
		tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
	else
		tp.Privileges[0].Attributes = 0;

	bool bSuccess = false;
	HANDLE hToken = NULL;
	if(::OpenProcessToken(::GetCurrentProcess(), TOKEN_WRITE, &hToken))
	{
		bSuccess = (::AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL) == TRUE);
		::CloseHandle(hToken);	
	}
	return bSuccess;
}

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

STDMETHODIMP CPSLPrivilege::get_Name(BSTR * pValue)
{
	PSL_BEGIN

	*pValue = m_sName.copy();

	PSL_END
}

STDMETHODIMP CPSLPrivilege::get_Enabled(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = m_bEnabled?VARIANT_TRUE:VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLPrivilege::put_Enabled(VARIANT_BOOL newValue)
{
	PSL_BEGIN

	bool bEnabling = newValue?true:false;
	if(m_bEnabled != bEnabling)
	{
		if(EnablePrivilege(bEnabling))
			m_bEnabled = bEnabling;
	}

	PSL_END
}

STDMETHODIMP CPSLPrivilege::get_Default(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = m_bDefault?VARIANT_TRUE:VARIANT_FALSE;

	PSL_END
}

STDMETHODIMP CPSLPrivilege::get_Removed(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = m_bRemoved?VARIANT_TRUE:VARIANT_FALSE;
	
	PSL_END
}

STDMETHODIMP CPSLPrivilege::get_UsedForAccess(VARIANT_BOOL * pValue)
{
	PSL_BEGIN

	*pValue = m_bUsedForAccess?VARIANT_TRUE:VARIANT_FALSE;
	
	PSL_END
}

STDMETHODIMP CPSLPrivilege::get_LUID(VARIANT * pValue)
{
	PSL_BEGIN

	CPSLUtilities::SetVariant64Bit(pValue, LUID_TO_QWORD(m_Luid));

	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
Web01 | 2.8.170713.1 | Last Updated 22 Nov 2010
Article Copyright 2008 by Vitaly Tomilov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid