windows 如何让 PowerShell 显示注册表数据值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2374674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get PowerShell to display registry Data values
提问by Guy Thomas
Take the Winlogon registry section, I would like PowerShell to display the Data value for DefaultUserName.
以 Winlogon 注册表部分为例,我希望 PowerShell 显示 DefaultUserName 的数据值。
This is as far as I have got:
这是据我所知:
Stage 1
阶段1
get-itemproperty -path "hklm:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"
Stage 2
第二阶段
I can append:
我可以附加:
-Name DefaultUserName
But this won't return a value.
但这不会返回值。
Also other Names, despite being visible in regedit, don't show in PowerShell, for example AutoAdminLogon.
还有其他名称,尽管在 regedit 中可见,但不会在 PowerShell 中显示,例如 AutoAdminLogon。
Question: how can make PowerShell display what I can see with regedit?
问题:如何让 PowerShell 显示我可以使用 regedit 看到的内容?
回答by Frank Bollack
You can try the standard command line:
您可以尝试标准命令行:
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName
回答by must21
even simpler:
更简单:
gp "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\").DefaultUserName
回答by Guy Thomas
I tried the very same commands on another machine, they worked perfectly, as expected. Thus my original machine must have a faulty registry, or at the least, weird permissions.
我在另一台机器上尝试了完全相同的命令,它们按预期完美运行。因此,我原来的机器必须有一个错误的注册表,或者至少是奇怪的权限。
回答by Massimo
A late followup.
一个迟到的跟进。
As suggested by Frank, REG.EXE works fine.
正如 Frank 所建议的,REG.EXE 工作正常。
However a small C function fail to read this specific DefaultUserName: the API RegQueryValueExA doesn't return error, but a size of 1 bytes !
然而,一个小的 C 函数无法读取这个特定的DefaultUserName:API RegQueryValueExA 不返回错误,而是 1 个字节的大小!
Under the same branch, I can read Shell.
在同一个分支下,我可以读取Shell。
With REGEDIT.EXE I check the permissions, for both values they are
使用 REGEDIT.EXE 我检查权限,对于这两个值,它们都是
Administrators : Full, Users : Read.
管理员:完整,用户:阅读。
OS : Windows 7 home premium - 64 bit
操作系统:Windows 7 家庭高级版 - 64 位
DWORD RegGetValueA( HKEY hTree, LPCSTR lpSubKey, LPCSTR lpValueName, LPDWORD lpdwType, LPVOID lpData, LPDWORD lpdwSize )
{
#define KEY_WOW64_32KEY 0x0200 // on 64-bit Windows should operate on the 32-bit registry view ( HKLM\SOFTWARE\Wow6432Node\... )
#define KEY_WOW64_64KEY 0x0100 // on 64-bit Windows should operate on the 64-bit registry view
DWORD ret, dwAlter = 0;
HKEY hKey;
retry:
ret = RegOpenKeyExA( hTree, lpSubKey, 0, KEY_READ | dwAlter, &hKey );
if ( ret != ERROR_SUCCESS )
return ret;
ret = RegQueryValueExA( hKey, lpValueName, NULL, lpdwType, lpData, lpdwSize );
RegCloseKey( hKey );
if ( ret != ERROR_SUCCESS && dwAlter == 0 )
{
dwAlter = KEY_WOW64_64KEY;
// printf( "retry... %d\r\n", dwAlter );
goto retry;
}
return ret;
}
回答by rerun
Does
做
Get-ItemProperty -path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\" |% {$_.DefaultUserName}
Work for you
为你工作