gpt4 book ai didi

powershell - OpenRemoteBaseKey() 凭据

转载 作者:行者123 更新时间:2023-12-04 01:02:58 35 4
gpt4 key购买 nike

我正在尝试使用 powershell 访问远程注册表,如下所示:

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $server)
$key = $reg.OpenSubkey($subkeyPath)

根据一些我还无法确定的因素,我要么得到

Exception calling "OpenSubKey" with "1" argument(s): "Requested registry access is not allowed."



或者

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation. at Microsoft.Win32.RegistryKey.Win32ErrorStatic(Int32 errorCode, String str) at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(RegistryHive hKey, String machineName)



很明显,这是因为我正在运行 powershell 脚本的用户没有访问远程注册表的适当凭据。我希望能够提供一组用于远程注册表访问的凭据,但我找不到任何文档来说明如何执行此操作。我也不清楚具体在哪里指定允许哪些用户远程访问注册表。

最佳答案

只是想我也会向任何有此问题的人添加我的答案。似乎无法使用 RemoteRegistry 添加凭据。但是,您可以使用 WMI 使用备用凭据查询远程注册表,如下所示:

$reg = Get-WmiObject -List -Namespace root\default -ComputerName RemotePC -Credential "Domain\User" | Where-Object {$_.Name -eq "StdRegProv"}

从这里您可以调用标准的注册表方法。下面的示例将返回操作系统。
$HKLM = 2147483650
$reg.GetStringValue($HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName").sValue

希望这对某人有所帮助:)

关于powershell - OpenRemoteBaseKey() 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1133335/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com