// Performacnce Monitor Routines


//
//	Adds Performance Monitor Reg Params and Counters to the service
//
//		$0 = Option
//
[InstallPerfMon]

	set Option = $($0)

	read-syms DriverConstants
	read-syms DriverConstants-$(Option)

	_Enter("InstallPerfMon", _Show(Option))

	// Set up the Registry
	_OpenRegKey_HKLM($(!NTN_ServiceBase)"\\"$(ProductSoftwareName), KeyDriverService)
	_IfNotValidKey($(KeyDriverService))
       _AssertMsg(FALSE, "No Driver Key")
	endif

	_MakeStdRegKey($(KeyDriverService), "Performance", KeyPerformance)
	_IfNotValidKey($(KeyPerformance))
		   _AssertGoto(FALSE, "Cannot mke the performance key")
	endif

	_SetRegSzByKey $(KeyPerformance) "Library" $(PerfLibrary)
    _Assert($($R0))
	_SetRegSzByKey $(KeyPerformance) "Open"    $(PerfOpen)
    _Assert($($R0))
	_SetRegSzByKey $(KeyPerformance) "Collect" $(PerfCollect)
    _Assert($($R0))
	_SetRegSzByKey $(KeyPerformance) "Close"   $(PerfClose)
    _Assert($($R0))

	CloseRegKey $(KeyDriverService)
	
	// Load the Counters.
	LoadLibrary "x" $(!STF_WINDOWSSYSPATH)\DigiDlg.dll !DIGIDLGHANDLE
    Set FLibraryErrCtl = 1
    LibraryProcedure Result $(!DIGIDLGHANDLE) PerfMonUtilities $(!STF_WINDOWSSYSPATH)"\\lodctr.exe "$(PerfLoadIni)
    Set FLibraryErrCtl = 0
 	_Trace("InstallPerfMon", _Show(Result))
	FreeLibrary $(!DIGIDLGHANDLE)

	// Install the Perfmon EventLog
	_OpenRegKey_HKLM($(!NTN_ServiceBase)"\\EventLog\\System", KeyEventLog)
	_IfNotValidKey($(KeyEventLog))
       _AssertMsg(FALSE, "No Event Log Key")
	else

		_MakeStdRegKey($(KeyEventLog), $(PerfEventLog), KeyEventLogAppl)
		Ifstr $(KeyEventLogAppl) != ""
			_SetRegExpandSzByKey $(KeyEventLogAppl) "EventMessageFile"   "%SystemRoot%\\System32\\"$(PerfLibrary)
			_Assert($($R0))
			set TypesSupported = 7
			_SetRegDwordByKey $(KeyEventLogAppl) "TypesSupported" $(TypesSupported)
			_Assert($($R0))
       endif

	endif

	_Exit("InstallPerfMon", "")
	Return

//
//	Adds Performance Monitor Reg Params and Counters to the service
//
//		$0 = Option
//
[UnInstallPerfMon]

	set Option = $($0)

	read-syms DriverConstants
	read-syms DriverConstants-$(Option)

	_Enter("UnInstallPerfMon", _Show(Option))
	
	// UnLoad the Counters.
	LoadLibrary "x" $(!STF_WINDOWSSYSPATH)\DigiDlg.dll !DIGIDLGHANDLE
    Set FLibraryErrCtl = 1
    LibraryProcedure Result $(!DIGIDLGHANDLE) PerfMonUtilities $(!STF_WINDOWSSYSPATH)"\\unlodctr.exe "$(ProductHardwareName)
    Set FLibraryErrCtl = 0
 	_Trace("UnInstallPerfMon", _Show(Result))
	FreeLibrary $(!DIGIDLGHANDLE)

	// DeInstall the Perfmon EventLog
	_OpenRegKey_HKLM($(!NTN_ServiceBase)"\\EventLog\\System", KeyEventLog)
	_IfNotValidKey($(KeyEventLog))
       _AssertMsg(FALSE, "No Event Log Key")
	else
		DeleteRegTree $(KeyEventLog) $(PerfEventLog)
	endif

	_Exit("UnInstallPerfMon", "")
	Return
