我正在尝试列出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 ++获得相同的输出?

最佳答案

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

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


您可以显式运行提升权限的程序,例如右键单击exe /快捷方式,然后单击“以管理员身份运行”。请注意,在Visual Studio中,您可以以管理员身份运行VS本身。
如果您的程序始终需要运行提升权限,则可以在VS中的“链接器”->“清单文件”上进行设置,例如“ UAC执行级别”选项,“ highestAvailable”或“ requireAdministrator”选项可能有用。
如果要启动子进程,则可以选择在此时提升位置,例如使用ShellExecuteEx,这将在需要时导致UAC弹出窗口。

关于c++ - 使用C++显示C:\Windows\System32\config的内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59360532/

10-11 22:01
查看更多