簡體   English   中英

使用 C++ 顯示 C:\Windows\System32\config 的內容

[英]Show contents of C:\Windows\System32\config using C++

我正在嘗試列出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();
}

兩者都給我相同的 output:

C:\Windows\System32\config\ELAM

C:\Windows\System32\config\日志

C:\Windows\System32\config\RegBack

C:\Windows\System32\config\systemprofile

C:\Windows\System32\config\TxR

文件管理器向我顯示了這個 output:

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\日志

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

C:\Windows\System32\config\RegBack

C:\Windows\System32\config\SAM

C:\Windows\System32\config\安全

C:\Windows\System32\config\軟件

C:\Windows\System32\config\SYSTEM

C:\Windows\System32\config\systemprofile

C:\Windows\System32\config\TxR

C:\Windows\System32\config\VSMIDK

操作系統:Windows 10

問題是如何使用 C++ 獲得相同的 output?

這可能是權限問題,如果您在資源管理器的屬性窗口中查看“安全”選項卡,您可能會看到某些文件對“用戶”組具有“讀取”權限,但某些文件僅具有“系統”權限”和“管理員”。

當您在 Windows 中運行程序時,即使是從管理員帳戶運行,它通常也不會提升運行,因此它無法訪問那些具有更受限權限的文件。

  • 您可以顯式運行提升的程序,例如右鍵單擊 exe/快捷方式並“以管理員身份運行”。 請注意,對於 Visual Studio,您可以以管理員身份運行 VS 本身。

  • 如果您的程序始終需要運行提升,您可以將其設置為這樣,在 VS 中,在“鏈接器”->“清單文件”上有“UAC 執行級別”選項,“highestAvailable”或“requireAdministrator”選項可能有用。

  • 如果您正在啟動一個子進程,您可以選擇在此時提升,例如使用ShellExecuteEx ,這將在需要時導致 UAC 彈出窗口。

我終於在 1 年零 9 個月后找到了解決方案。

當我嘗試列表文件時,我正在構建一個 32 位應用程序並且有 Wow64 重定向。 有兩種方法可以解決此問題:

  1. 構建 64 位應用程序
  2. 禁用重定向

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM