-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inaccessible performance counters (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009) #951
Comments
Which applications, exactly? |
https://github.com/sp00n/corecycler It's written in Power Shell. |
this is a pretty strange issue, a windows NT call, on this key is always failing even without the sandbox
the problem is that sandboxie needs this call for som functionality, I can use NtQueryObject instead but I have to check if this can cause any other issues |
using NtQueryObject the script still doe snot work but it seam to fail much later |
you can try the 0.8.5 build if you can pin point where it now crashes i can look into fixing the next proglem with this script |
Update: there are some performance issues in 0.8.5, so you might want to wait the next release: |
@birdie-github any update on that issue? |
Running:
|
Author of CoreCycler here, subscribing to this thread. The Performance Counters can become corrupted in Windows (for reasons unknown to me), normally the key Since Microsoft in its infinite wisdom decided that the id:name pairs can be dynamic and are localized, each computer can have a unique order of the strings, and CoreCycler tries to find the relevant ones first in the English registry entry (009) and then use the id to get the localized name (CurrentLanguage) to be able to query the Performance Counters from Windows (which uses the localized names and not the id), |
well the problem with Perflib\009 seams solved with the "UseObjectNameForKeys=y" setting the next issue is a different one, |
I'm not sure what you mean with second issue, but this PowerShell code would try to access the registry keys: $directory = $env:TEMP
$fileEnglish = $directory + '\_performanceCounters.English.txt'
$fileLocalized = $directory + '\_performanceCounters.Localized.txt'
$keyEnglish = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
$keyLocalized = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage'
$countersEnglish = (Get-ItemProperty -Path $keyEnglish -Name Counter).Counter
$countersLocalized = (Get-ItemProperty -Path $keyLocalized -Name Counter).Counter
cd $directory
Set-Content -Path $fileEnglish -Value $countersEnglish
Set-Content -Path $fileLocalized -Value $countersLocalized And this would roughly be the function that's used in CoreCycler: function Get-PerformanceCounterIDs {
param (
[Parameter(Mandatory=$true)]
[Array]
$englishCounterNames
)
$key = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
$allCounters = (Get-ItemProperty -Path $key -Name Counter).Counter
$numCounters = $allCounters.Count
$countersHash = @{}
# The string contains two-line pairs
# The first line is the ID
# The second line is the name
for ($i = 0; $i -lt $numCounters; $i += 2) {
$counterId = [Int]$allCounters[$i]
$counterName = [String]$allCounters[$i+1]
if ($englishCounterNames.Contains($counterName) -and !$countersHash.ContainsKey($counterName)) {
$countersHash[$counterName] = $counterId
}
}
return $countersHash
}
function Get-PerformanceCounterLocalName {
param (
[UInt32]
$ID,
$ComputerName = $env:COMPUTERNAME
)
try {
$code = '[DllImport("pdh.dll", SetLastError=true, CharSet=CharSet.Unicode)] public static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, System.Text.StringBuilder szNameBuffer, ref uint pcchNameBufferSize);'
$Buffer = New-Object System.Text.StringBuilder(1024)
[UInt32]$BufferSize = $Buffer.Capacity
$t = Add-Type -MemberDefinition $code -PassThru -Name PerfCounter -Namespace Utility
$rv = $t::PdhLookupPerfNameByIndex($ComputerName, $ID, $Buffer, [Ref]$BufferSize)
'ID: ' + $ID
'Found String: ' + $Buffer
if ($rv -eq 0) {
'Final Result:'
$Buffer.ToString().Substring(0, $BufferSize-1)
}
else {
Throw 'Get-PerformanceCounterLocalName : Unable to retrieve localized name. Check computer name and performance counter ID.'
}
}
catch {
'ERROR!'
$Error
$Error.Clear()
}
}
$englishCounterNames = @(
'Process',
'ID Process',
'% Processor Time'
)
$counterNames = @{}
$counterNameIds = Get-PerformanceCounterIDs $englishCounterNames
''
''
'-----------------'
'Counter Name IDs:'
'-----------------'
$counterNameIds
''
''
'------------------------'
'Localized Counter Names:'
'------------------------'
Get-PerformanceCounterLocalName $counterNameIds['Process']
Get-PerformanceCounterLocalName $counterNameIds['ID Process']
Get-PerformanceCounterLocalName $counterNameIds['% Processor Time'] |
@sp00n So once we have this working fine the CoreCycler however runs into an other IMHO unrelated crash:
|
@DavidXanatos Sometimes these Performance Counters will be corrupted for whatever reason, in which case you need to rebuild those (I've explained a way how to do so in the readme.txt mentioned in the error message). The code I posted above can be saved as a .ps1 script and then executed, and should give you an indication whether it's related to Sandboxie or not (there should be no error messages). |
I've updated my older Sandboxie installation now (didn't even know it had gone open source), and made some tests. The script fails in the following section: $code = '[DllImport("pdh.dll", SetLastError=true, CharSet=CharSet.Unicode)] public static extern UInt32 PdhLookupPerfNameByIndex(string szMachineName, uint dwNameIndex, System.Text.StringBuilder szNameBuffer, ref uint pcchNameBufferSize);'
$Buffer = New-Object System.Text.StringBuilder(1024)
[UInt32]$BufferSize = $Buffer.Capacity
$t = Add-Type -MemberDefinition $code -PassThru -Name PerfCounter -Namespace Utility
$rv = $t::PdhLookupPerfNameByIndex($ComputerName, $ID, $Buffer, [Ref]$BufferSize) The |
I've discovered that I cannot use applications which query
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009
- they receive access denied.I've tried granting
ANONYMOUS LOGON
and evenEVERYONE
the permission to read this registry path (to be preciseHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
as009
inherits it) but it didn't work.Please advise. I'm not sure if it's an actual bug.
The text was updated successfully, but these errors were encountered: