ANAVEM
Languagefr
Windows Performance Monitor displaying system performance counters and metrics on multiple monitors
Event ID 2004ErrorPerflibWindows

Windows Event ID 2004 – Perflib: Performance Counter Provider Registration Failed

Event ID 2004 indicates a performance counter provider failed to register with the Windows Performance Toolkit. This typically occurs when performance counter DLLs are corrupted, missing, or incompatible with the current system.

Emanuel DE ALMEIDAEmanuel DE ALMEIDA
18 March 202612 min read 0
Event ID 2004Perflib 5 methods 12 min
Event Reference

What This Event Means

Windows Event ID 2004 represents a critical failure in the performance counter subsystem where a specific counter provider cannot register with the Performance Library (Perflib). The Performance Library serves as the central registry for all performance counters in Windows, managing the collection and distribution of performance data to monitoring applications.

When this event occurs, Windows logs detailed information including the counter provider name, the specific DLL that failed to load, and often an accompanying error code. Common error codes include 0x80070002 (file not found), 0x8007007E (module not found), or 0x80070005 (access denied). These codes provide valuable clues for troubleshooting the underlying issue.

The impact of this event varies depending on which counter provider failed. System-critical counters like Processor, Memory, or LogicalDisk failures can significantly impact monitoring capabilities, while third-party application counters may only affect specific monitoring scenarios. In enterprise environments, this event can trigger monitoring alerts and may indicate broader system health issues that require immediate attention.

Performance counter registration failures often cascade, meaning one failed provider can prevent others from loading correctly. This creates a domino effect where multiple Event ID 2004 entries appear in rapid succession, each representing a different failed counter provider.

Applies to

Windows 10Windows 11Windows Server 2019/2022/2025
Analysis

Possible Causes

  • Corrupted or missing performance counter DLL files
  • Registry corruption in performance counter configuration keys
  • Insufficient permissions for the performance counter service
  • Version incompatibility between counter providers and Windows build
  • Failed Windows updates that damaged performance counter infrastructure
  • Third-party software installing incompatible performance counters
  • Antivirus software blocking or quarantining performance counter DLLs
  • Disk corruption affecting system files or registry
  • Service dependencies not starting correctly during boot
  • Memory corruption affecting DLL loading processes
Resolution Methods

Troubleshooting Steps

01

Identify Failed Counter Provider in Event Viewer

Start by examining the specific details of Event ID 2004 to identify which performance counter provider failed.

  1. Open Event Viewer by pressing Win + R, typing eventvwr.msc, and pressing Enter
  2. Navigate to Windows LogsSystem
  3. Filter the log for Event ID 2004 by right-clicking the System log and selecting Filter Current Log
  4. Enter 2004 in the Event IDs field and click OK
  5. Double-click the most recent Event ID 2004 entry to view details
  6. Note the counter provider name and any error codes in the event description
  7. Use PowerShell to get detailed event information:
Get-WinEvent -FilterHashtable @{LogName='System'; Id=2004} -MaxEvents 5 | Format-List TimeCreated, Id, LevelDisplayName, Message

Record the specific counter provider name and error code for use in subsequent troubleshooting steps.

02

Rebuild Performance Counter Registry

Rebuild the performance counter registry to fix corrupted counter configurations.

  1. Open Command Prompt as Administrator
  2. Stop the Performance Logs and Alerts service:
net stop pla
  1. Navigate to the system32 directory and rebuild counters:
cd /d %windir%\system32
lodctr /R
  1. If the rebuild fails, reset the performance counter repository:
winmgmt /resyncperf
  1. Restart the Performance Logs and Alerts service:
net start pla
  1. Verify the fix by checking if new Event ID 2004 entries appear after reboot
  2. Use PowerShell to confirm counter providers are loading:
Get-Counter -ListSet * | Where-Object {$_.CounterSetName -like "*Processor*"} | Select-Object CounterSetName, Description
Warning: The lodctr /R command rebuilds all performance counters and may take several minutes to complete.
03

Check and Repair Performance Counter DLL Files

Verify the integrity of performance counter DLL files and repair if necessary.

  1. Identify the specific DLL mentioned in the Event ID 2004 error message
  2. Check if the DLL exists in the expected location:
$dllPath = "C:\Windows\System32\[CounterDLL].dll"
Test-Path $dllPath
Get-ItemProperty $dllPath | Select-Object Name, Length, LastWriteTime
  1. Run System File Checker to repair corrupted system files:
sfc /scannow
  1. If SFC finds issues, run DISM to repair the Windows image:
DISM /Online /Cleanup-Image /RestoreHealth
  1. Check the performance counter registry entries:
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009" | Select-Object Counter, Help
  1. If the DLL is missing, extract it from a Windows installation source or use:
sxstrace trace -logfile:C:\temp\sxstrace.etl
# Reproduce the error, then:
sxstrace parse -logfile:C:\temp\sxstrace.etl -outfile:C:\temp\sxstrace.txt
  1. Restart the system and monitor for Event ID 2004 recurrence
04

Reset Performance Counter Permissions and Services

Reset permissions and service configurations for the performance counter subsystem.

  1. Open Services.msc and verify these services are running:
  2. Performance Logs and Alerts (pla)
  3. Windows Management Instrumentation (winmgmt)
  4. Reset WMI repository if performance counters are WMI-based:
net stop winmgmt /y
winmgmt /resetrepository
net start winmgmt
  1. Check and reset performance counter permissions:
$acl = Get-Acl "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib"
$acl.Access | Format-Table IdentityReference, FileSystemRights, AccessControlType
  1. Grant necessary permissions to the Performance Counter Users group:
net localgroup "Performance Log Users" /add "NT AUTHORITY\INTERACTIVE"
net localgroup "Performance Monitor Users" /add "NT AUTHORITY\INTERACTIVE"
  1. Reset the performance counter security descriptor:
lodctr /S:"C:\temp\perfcounters_backup.ini"
lodctr /R:"C:\temp\perfcounters_backup.ini"
  1. Restart the system and verify performance counter functionality:
Get-Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 3
Pro tip: Always backup the performance counter configuration before making changes using lodctr /S.
05

Advanced Registry Analysis and Third-Party Counter Removal

Perform advanced troubleshooting by analyzing registry corruption and removing problematic third-party counters.

  1. Export the performance counter registry for analysis:
reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib" C:\temp\perflib_backup.reg
  1. Analyze the performance counter registry structure:
$perflib = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib"
$perflib | ForEach-Object {
    $lang = $_.PSChildName
    $counters = Get-ItemProperty $_.PSPath -Name "Counter" -ErrorAction SilentlyContinue
    if ($counters) {
        Write-Output "Language: $lang, Counter entries: $($counters.Counter.Count)"
    }
}
  1. Identify and remove problematic third-party performance counters:
$services = Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\*" | Where-Object {$_.ObjectName -like "*PerfCounter*"}
$services | Select-Object PSChildName, DisplayName, ObjectName
  1. Remove specific counter providers that are causing issues:
unlodctr "[CounterProviderName]"
  1. Check for orphaned performance counter entries:
$orphaned = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009" -Name "Counter" | 
    ForEach-Object {$_.Counter} | Where-Object {$_ -match "[0-9]+"} | 
    ForEach-Object {if (!(Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\$_" -ErrorAction SilentlyContinue)) {$_}}
$orphaned
  1. Clean up orphaned entries and rebuild the counter database:
lodctr /R
winmgmt /resyncperf
  1. Monitor system performance and verify all critical counters are functional:
$criticalCounters = @("\Processor(_Total)\% Processor Time", "\Memory\Available MBytes", "\LogicalDisk(_Total)\% Disk Time")
$criticalCounters | ForEach-Object {
    try {
        Get-Counter $_ -MaxSamples 1
        Write-Output "$_ - OK"
    } catch {
        Write-Output "$_ - FAILED: $($_.Exception.Message)"
    }
}
Warning: Removing performance counters can affect monitoring applications. Always test in a non-production environment first.

Overview

Event ID 2004 from the Perflib source fires when Windows fails to register a performance counter provider during system startup or service initialization. This event typically appears in the System log and indicates that a specific performance counter DLL could not be loaded or initialized properly. The event contains details about which counter provider failed and often includes error codes that help identify the root cause.

Performance counters are essential for system monitoring, providing real-time metrics about CPU usage, memory consumption, disk I/O, and application performance. When a counter provider fails to register, you lose visibility into specific system metrics, which can impact monitoring tools like Performance Monitor, System Monitor, and third-party monitoring solutions.

This event commonly occurs after Windows updates, driver installations, or when third-party applications install custom performance counters. The failure can stem from corrupted registry entries, missing DLL files, permission issues, or version incompatibilities between the counter provider and the current Windows build.

Frequently Asked Questions

What does Event ID 2004 mean and why does it occur?+
Event ID 2004 indicates that a performance counter provider failed to register with Windows Performance Library (Perflib). This occurs when performance counter DLLs are corrupted, missing, have incorrect permissions, or are incompatible with the current Windows version. The event typically appears during system startup when Windows attempts to initialize all registered performance counters.
How can I identify which specific performance counter is causing Event ID 2004?+
Open Event Viewer and navigate to Windows Logs → System. Filter for Event ID 2004 and examine the event details. The error message will specify the counter provider name and often include the DLL filename. You can also use PowerShell: Get-WinEvent -FilterHashtable @{LogName='System'; Id=2004} | Format-List Message to see detailed information about failed counter providers.
Is Event ID 2004 critical and will it affect system performance?+
Event ID 2004 is an error-level event but typically doesn't affect core system functionality. However, it can impact monitoring capabilities and may indicate underlying system issues. If critical system counters like Processor, Memory, or Disk fail to load, monitoring tools won't display accurate performance data. Third-party application counters failing usually only affects specific monitoring scenarios.
Can I safely ignore Event ID 2004 or should I fix it immediately?+
While Event ID 2004 won't cause system crashes, you should investigate and resolve it promptly. Failed performance counters can indicate registry corruption, missing system files, or permission issues that might worsen over time. In enterprise environments, this event can trigger monitoring alerts and may prevent proper system health monitoring, making it difficult to detect performance problems.
What should I do if lodctr /R doesn't resolve Event ID 2004?+
If rebuilding performance counters with lodctr /R doesn't work, try these advanced steps: 1) Run sfc /scannow to repair system files, 2) Use DISM /Online /Cleanup-Image /RestoreHealth to fix Windows image corruption, 3) Reset WMI repository with winmgmt /resetrepository, 4) Check for third-party software conflicts, and 5) Consider removing problematic third-party performance counters using unlodctr. If issues persist, the problem may require Windows repair or reinstallation.
Documentation

References (2)

Emanuel DE ALMEIDA
Written by

Emanuel DE ALMEIDA

Senior IT Journalist & Cloud Architect

Microsoft MCSA-certified Cloud Architect | Fortinet-focused. I modernize cloud, hybrid & on-prem infrastructure for reliability, security, performance and cost control - sharing field-tested ops & troubleshooting.

Discussion

Share your thoughts and insights

You must be logged in to comment.

Loading comments...