如果我打电话
REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI
然后在批处理脚本中显示正确的结果:
ShowTabletKeyboard REG_DWORD 0x0
LastLoggedOnProvider REG_SZ {???}
LastLoggedOnSAMUser REG_SZ foo\bar
LastLoggedOnUser REG_SZ .\bar
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonU \Background
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\BootAnimation
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LogonSoundPlayed
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData
如果我从 c 程序 (mingw) 中运行上面的命令:
#include <stdio.h>
#include <unistd.h>
int main(void) {
system("REG QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI");
return (0);
}
输出是
ShowTabletKeyboard REG_DWORD 0x0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\Background
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\BootAnimation
其余的输出在哪里?哪些权限是错误的?我对键 LastLoggedOnUser 很感兴趣。非常感谢。
最佳答案
这是 registry redirector 的 Action .你有一个 64 位系统。批处理文件由 native 64 位命令解释器执行。但是您的 C 程序是 32 位的,system
命令作为 32 位进程运行。发生这种情况是因为当您在 64 位 Windows 上运行 32 位进程时,文件重定向器会将 system32 转换为 syswow64。
所有这些都意味着 C 程序正在读取注册表的 32 位 View 。您尝试阅读 HKLM\Software
被重定向到 HKLM\Software\Wow6432Node
。
理想的解决方案是停止使用 system
并使用 native Windows API 函数来访问注册表。然后你可以指定你想从注册表的 64 位 View 中读取,你甚至可以从 32 位进程访问它。
一个完全令人反感的 hack 是让你的 system
命令启动 %SystemRoot%\Sysnative\reg.exe
这将强制使用 64 位版本的reg
.
关于c - 执行 "reg query"作为新进程不显示所有键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433928/