SecPerf Sample: Regulate Access to the Performance Data

Click to open or copy the files for the SecPerf sample.

The SecPerf sample illustrates how to regulate access to the performance data provided by the registry key HKEY_PERFORMANCE_DATA.

The security on the following registry key dictates which users or groups can gain access to the performance data:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib

This sample opens the registry key for WRITE_DAC access, which allows for a new Dacl to be applied to the registry key.

A Dacl is then built, which grants the following users access:

Administrators are granted full control to allow for future updates to the security on the key and to allow for querying performance data.

Interactively logged on users, through the well-known Interactive Sid, are granted KEY_READ access, which allows for querying performance data.

The new Dacl is then applied to the registry key using the RegSetKeySecurity Win32 API.

This sample relies on the import library Advapi32.lib.

Building SDK Samples

This sample uses the following keywords:

addaccessallowedace; allocateandinitializesid; displaywinerror; formatmessagea; fprintf; freesid; getlasterror; getlengthsid; getprocessheap; getstdhandle; heapalloc; heapfree; initializeacl; initializesecuritydescriptor; localfree; makelangid; printf; regclosekey; regopenkeyex; regsetkeysecurity; setsecuritydescriptordacl; text; writefile