pdhenumobjectsw问题
我在枚举性能计数器对象方面有一个问题。我的代码运行良好几年,但是最近我发现它开始无法获得以下错误的计数器对象:
pdh_cstatus_no_machine 路径不包含计算机名称,并且该功能无法检索本地计算机名称。
DWORD bufLength = 0;
const DWORD detailLevel = PERF_DETAIL_WIZARD;
PDH_STATUS objStatus = PdhEnumObjectsW(nullptr, nullptr, nullptr, &bufLength, detailLevel, TRUE);
qDebug() << ManageApp::getPdhStatusMsg(objStatus);
qDebug() << "bufLength: " << bufLength;
std::wstring namebuf(bufLength, '\0');
PDH_STATUS status = PdhEnumObjectsW(nullptr, nullptr, &namebuf[0], &bufLength, detailLevel, FALSE);
qDebug() << ManageApp::getPdhStatusMsg(status);
我试图获取计算机名称并将其设置在pdhenumobjectsw()
调用:
PDH_STATUS objStatus = PdhEnumObjectsW(nullptr, machineName.toStdWString().c_str(), nullptr, &bufLength, detailLevel, TRUE);
WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD computerNameSize = _countof(computerName);
bool isComputerName = GetComputerNameExW(ComputerNameDnsFullyQualified, computerName, &computerNameSize);
qDebug() << isComputerName;
QString machineName = "";
我已删除Windows 10更新并切换回19044.1645,但它仍然显示pdh_cstatus_no_no_no_machine
错误。另外,我已经在VM -Windows 10 Build 19043,Windows 11和Windows 11 Insider Preview中对其进行了检查,因此在那里运行良好。
来自以下错误描述:
pdh_cstatus_no_machine
无法连接到指定的计算机。可能是由于计算机未打开的,不支持PDH,不连接到网络引起的,或者在注册表上设置了权限,以防止用户进行远程连接或远程性能监视。
因此,我认为这与注册表权限有关。有什么想法如何验证我的机器上适当设置了PDH的所有注册表权限?
我已经检查了Computer \ Hkey_local_machine \ Software \ Microsoft \ Microsoft \ Windows NT \ CurrentVersion \ Perflib
的注册表权限,并且所有权限均正确设置。因此,我不认为这与注册表权限有关。
有什么想法会导致这样的pdh_cstatus_no_machine
问题?
I have an issue with enumerating performance counter objects. My code worked well for a few years, but recently I have found it started to fail to get counter objects with the following error:
PDH_CSTATUS_NO_MACHINE The path did not contain a computer name, and the function was unable to retrieve the local computer name.
DWORD bufLength = 0;
const DWORD detailLevel = PERF_DETAIL_WIZARD;
PDH_STATUS objStatus = PdhEnumObjectsW(nullptr, nullptr, nullptr, &bufLength, detailLevel, TRUE);
qDebug() << ManageApp::getPdhStatusMsg(objStatus);
qDebug() << "bufLength: " << bufLength;
std::wstring namebuf(bufLength, '\0');
PDH_STATUS status = PdhEnumObjectsW(nullptr, nullptr, &namebuf[0], &bufLength, detailLevel, FALSE);
qDebug() << ManageApp::getPdhStatusMsg(status);
I have tried to get the computer name and set it in the PdhEnumObjectsW()
call:
PDH_STATUS objStatus = PdhEnumObjectsW(nullptr, machineName.toStdWString().c_str(), nullptr, &bufLength, detailLevel, TRUE);
WCHAR computerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD computerNameSize = _countof(computerName);
bool isComputerName = GetComputerNameExW(ComputerNameDnsFullyQualified, computerName, &computerNameSize);
qDebug() << isComputerName;
QString machineName = "";
I have removed the Windows 10 update and switched back to 19044.1645, but it still displays the PDH_CSTATUS_NO_MACHINE
error. Also, I have checked it in a VM - Windows 10 build 19043, Windows 11 and Windows 11 Insider Preview, so it works well there.
From the docs, I get following error description:
PDH_CSTATUS_NO_MACHINE
Unable to connect to the specified computer. Could be caused by the computer not being on, not supporting PDH, not being connected to the network, or having the permissions set on the registry that prevent remote connections or remote performance monitoring by the user.
So, I think it's somehow related to registry permissions. Any ideas how to verify that all registry permissions for PDH are properly set on my machine?
I have checked out the registry permissions for Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
, and all permissions are set properly. So, I do not think, it is related to the registry permissions.
Any ideas what could cause such PDH_CSTATUS_NO_MACHINE
issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过重建性能计数器来修复它。
说明:
使用此命令将“禁用性能计数器”设置为0:
reg添加hkey_local_machine \ system \ currentControlset \ services \ perfproc \ performand /v“ disable performance counters” /t reg_dword /d reg_dword /d 0 < /code> < /p>> < /p>
性能计数器:
%windir%\ system32 \ lodctr/r
%windir%\ syswow64 \ lodctr/r
在运行第一个命令 -
%
%windir%\ System32 \ lodctr /r < /code>,您将得到:
在这种情况下为2,请首先自由运行 -
%windir%\ syswow64 \ lodctr /r < /code>,然后运行
%windir%\ system32 \ lodctr /rodctr /r << /代码>。此命令之后的第二次:
%windir%\ syswow64 \ lodctr /r < /code>它将成功完成
>%windir%\ system32 \ lodctr /r < /code>:
ressync使用Windows Management Instrumentation(WMI)的计数器:
%Windir%\ System32 \ wbem \ winmgmt.exe/resyncperf
停止并重新启动性能日志,并使用以下命令:
net stop pla
net start pla
停止并重新启动Windows Management Instrumentation(WMI)服务这些命令:
网络停止winmgmt
网络启动winmgmt
因此,解决了问题。谢谢。
I have fixed it by rebuilding the performance counters.
Instructions:
Set "Disable Performance Counters" to 0 using this command:
Reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance /v "Disable Performance Counters" /t REG_DWORD /d 0
Rebuild all performance counters:
%windir%\system32\lodctr /R
%windir%\sysWOW64\lodctr /R
When running the first command -
%windir%\system32\lodctr /R
, you will get:In such case, feel free run this command first -
%windir%\sysWOW64\lodctr /R
and then run%windir%\system32\lodctr /R
. The second time after this command:%windir%\sysWOW64\lodctr /R
it will complete successfully for%windir%\system32\lodctr /R
:Resync the counters with Windows Management Instrumentation (WMI):
%windir%\system32\wbem\winmgmt.exe /resyncperf
Stop and restart the Performance Logs and Alerts service with the following commands:
net stop pla
net start pla
Stop and restart the Windows Management Instrumentation (WMI) service by using these commands:
net stop winmgmt
net start winmgmt
So, the issue is resolved. Thanks.