Click here to Skip to main content
15,896,111 members
Articles / Programming Languages / Visual Basic 6

Professional System Library: Introduction

Rate me:
Please Sign up or sign in to vote.
4.84/5 (93 votes)
22 Nov 2010CPOL14 min read 194.6K   3.4K   232  
A simplified and unified way for accessing most frequently used information about Process, System, and Environment.
// PSLWMI.h : Declaration of the CPSLWMI

#pragma once
#include "resource.h"       // main symbols
#include "GUIDs.h"
#include "PSLExceptions.h"
#include <Wbemcli.h>
#include "ProSysLib_i.h"

// CPSLWMI

class ATL_NO_VTABLE CPSLWMI :
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<CPSLWMI, &CLSID_PSLWMI>,
	public IDispatchImpl<IPSLWMI, &IID_IPSLWMI, &LIBID_ProSysLib, PSL_HiVersion, PSL_LoVersion>,
	public CPSLException<&CLSID_PSLWMI, &IID_IPSLWMI>
{
public:

	CPSLWMI();
	~CPSLWMI();

BEGIN_COM_MAP(CPSLWMI)
	COM_INTERFACE_ENTRY(IPSLWMI)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()
	HRESULT FinalConstruct();
	void FinalRelease();

////////////////////////////
// Interface Implementation:
////////////////////////////

	STDMETHOD(get_DefaultNamespace)(BSTR * pValue);
	STDMETHOD(put_DefaultNamespace)(BSTR newValue);
	STDMETHOD(get_DefaultImpersonationLevel)(PSLImpersonationLevel * pValue);
	STDMETHOD(get_InstallationDir)(BSTR * pValue);
	STDMETHOD(get_Version)(BSTR * pValue);
	STDMETHOD(get_LastError)(long * pValue);
	STDMETHOD(GetValue)(BSTR NameSpace, BSTR ClassName, BSTR ValueName, VARIANT * pValue);
	STDMETHOD(GetRowValues)(BSTR NameSpace, BSTR ClassName, BSTR ValueName, SAFEARRAY ** ppValue);
	STDMETHOD(GetColValues)(BSTR NameSpace, BSTR ClassName, BSTR ValueNameCSV, SAFEARRAY ** ppValue);
	STDMETHOD(GetColNames)(BSTR NameSpace, BSTR ClassName, SAFEARRAY ** ppValue);
	STDMETHOD(GetData)(BSTR NameSpace, BSTR WQL, IPSLTable ** ppValue);
	
private:

	_bstr_t m_sDefaultNamespace;
	PSLImpersonationLevel m_DefaultImpersonationLevel;
	_bstr_t m_sInstallationDir;
	_bstr_t m_sVersion;
	long m_LastError;

	CRITICAL_SECTION m_csLocator;
	CRITICAL_SECTION m_csServices;

	static bool ExtractSELECTDetails(LPCTSTR sQuery, tstring & sClassName, vector<tstring> & Columns, bool & bAllCols, bool & bHasSpecials);
	static bool GetWQLColumnsFromCSV(LPCTSTR sText, vector<tstring> & Columns);

	HRESULT RaiseWMIException(long lErrorCode);

	CComPtr<IWbemLocator> GetLocator(long & lErrorCode);
	CComPtr<IWbemServices> GetServices(BSTR NameSpace, long & lErrorCode);
	CComPtr<IEnumWbemClassObject> ExecuteQuery(BSTR NameSpace, LPCTSTR sWQL, long & lErrorCode);

	CComPtr<IWbemLocator> m_pLocator;
	CComPtr<IWbemServices> m_pServices;

	_bstr_t m_sServiceName; // Current service name in m_pServices;
};


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