Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / VBScript

ProSysLib: Dissecting the Process

Rate me:
Please Sign up or sign in to vote.
4.84/5 (69 votes)
22 Nov 2010CPOL12 min read 128.1K   2.6K   174  
Access detailed information about the current process the easiest way.
// PSLNetwork.cpp : Implementation of CPSLNetwork

#include "stdafx.h"
#include "PSLNetwork.h"
#include "PSLIPv4.h"
#include "PSLIPv6.h"
#include "ProSysModule.h"
#include <lm.h>

CPSLNetwork::CPSLNetwork()
{
	// Not needed yet!
	//_Module.InitWinSockets(); // Initialize WinSockets;

	tstring pcName;
	DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
	pcName.resize(dwSize);
	::GetComputerName((LPTSTR)pcName.c_str(), &dwSize);
	m_sPCName = pcName.c_str();
}

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

void CPSLNetwork::FinalRelease()
{
}

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

STDMETHODIMP CPSLNetwork::get_PCName(BSTR * pValue)
{
	PSL_BEGIN

	*pValue = m_sPCName.copy();
	
	PSL_END
}

STDMETHODIMP CPSLNetwork::get_DomainName(BSTR * pValue)
{
	PSL_BEGIN

	_bstr_t name(_T(""));
	LPWKSTA_INFO_100 pBuffer = NULL;
	DWORD dwStatus = ::NetWkstaGetInfo(NULL, 100, (LPBYTE*)&pBuffer);
	if(dwStatus == NERR_Success)
	{
		name = pBuffer->wki100_langroup;
		::NetApiBufferFree(pBuffer);
	}
	else
		if(dwStatus == ERROR_ACCESS_DENIED)
			return MakeException(exAccessDenied);

	*pValue = name.copy();

	PSL_END
}

STDMETHODIMP CPSLNetwork::IPv4FromString(BSTR Address, IPSLIPv4 ** ppValue)
{
	PSL_BEGIN

	*ppValue = NULL;
	CComObject<CPSLIPv4> * pIPv4 = NULL;
	if(CComObject<CPSLIPv4>::CreateInstance(&pIPv4) == S_OK)
	{
		pIPv4->AddRef();
		bool bValid = true;
		if(Address)
		{
			_bstr_t sAddress(_T(""));
			if(Address)
				sAddress = Address;
			bValid = pIPv4->Initialize(sAddress, true);
		}
		if(bValid)
			*ppValue = CComPtr<IPSLIPv4>(pIPv4);
		else
		{
			pIPv4->Release();
			SetException(exInvalidParameter);
		}
	}

	PSL_END
}

STDMETHODIMP CPSLNetwork::IPv6FromString(BSTR Address, IPSLIPv6 ** ppValue)
{
	PSL_BEGIN

	*ppValue = NULL;
	CComObject<CPSLIPv6> * pIPv6 = NULL;
	if(CComObject<CPSLIPv6>::CreateInstance(&pIPv6) == S_OK)
	{
		pIPv6->AddRef();
		bool bValid = true;
		if(Address)
		{
			_bstr_t sAddress(_T(""));
			if(Address)
				sAddress = Address;
			bValid = pIPv6->Initialize(sAddress, true);
		}
		if(bValid)
			*ppValue = CComPtr<IPSLIPv6>(pIPv6);
		else
		{
			pIPv6->Release();
			SetException(exInvalidParameter);
		}
	}

	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)


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

Comments and Discussions