c - 执行 "reg query"作为新进程不显示所有键

标签 c windows-7 registry

如果我打电话

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/

相关文章:

c++ - 当内部指针偏移量已知时,抑制 valgrind 中的 "possibly lost"错误

java - 在Windows中从命令行运行java的问题

c# - 以编程方式创建 Windows 用户 c# .net(使用 PricinpalUser/CreateProfile)

windows - 如何使用 cmd 在 Windows 7 中列出 CUDA 设备?

C RegEnumKeyExA 接收 ERROR_MORE_DATA 的问题

通过双指针转换分配的内存

c - 错误: dereferencing pointer to incomplete type when accessing struct

security - 检测到弱密码

java - Windows 7 防火墙 : Modify group items from command line

c - 是否可以在共享内存上加载共享库?