OpenRemoteBaseKey () Credentials

I am trying to use powershell to access a remote registry:

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

Depending on some factors that I still can’t determine, I either get

Raising the OpenSubKey exception with argument "1": "Requested registry access is not allowed."

or

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)

It seems pretty clear that this is due to the fact that the user I am running the powershell script, since it does not have the appropriate credentials to access the remote registry. I would like to be able to provide a set of credentials to use for remote access to the registry, but I cannot find any documentation anywhere for this. I also do not quite understand exactly where to specify which users can remotely access the registry.

+5
source share
7 answers

, . , 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

, -:)

+4

? , . , .

+1

bentaylr , , , PSCredentials ( ), script.

: script. , . (. ).

, , , , .

$user = "Domain\Username"
$pass = ConvertTo-SecureString "Password" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$pass

$reg = Get-WmiObject -List -Namespace root\default -ComputerName $server -Credential $cred | Where-Object {$_.Name -eq "StdRegProv"}
$HKLM = 2147483650
$value = $reg.GetStringValue($HKLM,"Software\Microsoft\.NetFramework","InstallRoot").sValue
+1
PS C:\>$regKey.OpenSubKey

OverloadDefinitions

Microsoft.Win32.RegistryKey OpenSubKey(string name, **bool Writable**)

PS C:\>$key.OpenSubKey($subkeyName,**$true**)

http://msdn.microsoft.com/en-us/library/xthy8s8d%28v=vs.110%29.aspx

+1

$key.OpenSubKey($ subkeyName) , $ key.OpenSubKey($ subkeyName, $true)

$key.OpenSubKey($ subkeyName, $true)

$key.OpenSubKey($ subkeyName), "UnauthorizedAccessException"

+1

, , - , String... , :

$machine = "<Machine Name Goes Here>"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type,$machine)
$subkey = $regKey.OpenSubKey($key)
foreach ($sub in $regKey.GetSubKeyNames()){$sub}
0

, , , Get-Credential script. script :

$userCredentials = Get-Credential -Credential <domain\username>
$objReg = Get-WmiObject -List -Namespace root\default -ComputerName $server -Credential $userCredentials | Where-Object{$_.Name -eq "StdRegProv"}
$subKeyNames = $objReg.EnumKey($HKLM,"SOFTWARE\Microsoft\Updates\Microsoft .Net Framework 4.5.1").sNames

, , , . $objReg, :

$objReg | Get-Member

, . , !

0

All Articles