使用 C++ 显示 C:\Windows\System32\config 的内容

Posted

技术标签:

【中文标题】使用 C++ 显示 C:\\Windows\\System32\\config 的内容【英文标题】:Show contents of C:\Windows\System32\config using C++使用 C++ 显示 C:\Windows\System32\config 的内容 【发布时间】:2019-12-16 16:24:00 【问题描述】:

我正在尝试列出C:\Windows\System32\config 目录的文件。

我试过像这样使用QDir::entryList()

QDir dir(R"(C:\Windows\System32\config)");
dir.setFilter(QDir::Hidden | QDir::AllEntries | QDir::System | QDir::NoDotAndDotDot);
qDebug().noquote() << dir.entryInfoList();

我也试过像这样使用std::filesystem::directory_iterator

std::string path = R"(C:\Windows\System32\config)";
for (const auto& entry : std::filesystem::directory_iterator(path))

    qDebug().noquote() << entry.path().string().c_str();

两者都给了我相同的输出:

C:\Windows\System32\config\ELAM

C:\Windows\System32\config\Journal

C:\Windows\System32\config\RegBack

C:\Windows\System32\config\systemprofile

C:\Windows\System32\config\TxR

文件管理器向我显示此输出:

C:\Windows\System32\config\BBI

C:\Windows\System32\config\BCD-模板

C:\Windows\System32\config\COMPONENTS

C:\Windows\System32\config\DEFAULT

C:\Windows\System32\config\DRIVERS

C:\Windows\System32\config\ELAM

C:\Windows\System32\config\Journal

C:\Windows\System32\config\netlogon.ftl

C:\Windows\System32\config\RegBack

C:\Windows\System32\config\SAM

C:\Windows\System32\config\SECURITY

C:\Windows\System32\config\SOFTWARE

C:\Windows\System32\config\SYSTEM

C:\Windows\System32\config\systemprofile

C:\Windows\System32\config\TxR

C:\Windows\System32\config\VSMIDK

操作系统:Windows 10

问题是如何使用 C++ 获得相同的输出?

【问题讨论】:

也许您没有访问这些文件的权限? @PaulMcKenzie 我是这么想的,但如果 Explorer 显示他们,那么他的用户帐户就有权限。我想知道这是否是一个提升的过程?但是我无法复制。 使用提升的权限从命令行运行您的程序。该目录的特殊之处在于(对我而言)需要管理员权限才能访问它。 嗯,奇怪,我的两个 Windows 虚拟机(Win10 和 2019)对这些文件有不同的权限...... 【参考方案1】:

这可能是权限问题,如果您在资源管理器的属性窗口中查看“安全”选项卡,您可能会看到某些文件对“用户”组具有“读取”权限,但有些文件只有权限用于“系统”和“管理员”。

当您在 Windows 中运行程序时,即使从管理员帐户运行,它通常也无需提升权限即可运行,因此它无法访问具有更多受限权限的文件。

您可以显式运行提升的程序,例如右键单击 exe/快捷方式和“以管理员身份运行”。请注意,对于 Visual Studio,您可以以管理员身份运行 VS。

如果您的程序总是需要运行提升,您可以这样设置,在 VS 中,在“链接器”->“清单文件”上有“UAC 执行级别”选项,“最高可用”或“requireAdministrator”选项可能有用。

如果您正在启动子进程,您可以选择在该点提升,例如使用ShellExecuteEx,如果需要,这将导致 UAC 弹出窗口。

【讨论】:

感谢您的回答。我已经以管理员身份运行应用程序并使用清单文件。我还检查了安全选项卡中的权限。管理员拥有文件夹的完全访问权限【参考方案2】:

时隔1年9个月,我终于找到了解决办法。

当我尝试使用列表文件时,我正在构建一个 32 位应用程序并且有 Wow64 重定向。有两种方法可以解决这个问题:

    构建 64 位应用程序 disable redirect

【讨论】:

以上是关于使用 C++ 显示 C:\Windows\System32\config 的内容的主要内容,如果未能解决你的问题,请参考以下文章

PermissionError:[Errno 13] 权限被拒绝:

Windows 10 上的 Bash 和 Ubuntu 终端有啥区别

Windows 2008 server R2安装.NET Framework4时提示“灾难性故障”解决

psql 说数据库不存在但它确实存在于 pgadmin

使用正则表达式和 Impala SQL 在最后一个 \\ 之后选择字符串

没有注册 OpKernel 以支持具有这些属性的 Op 'Conv2D'