Powershell Microsoft.win32.registrykey Openremotebasekey Credentials

Posted : admin On 4/30/2019
  1. Openremotebasekey Powershell

I'm attempting to use powershell to access a remote registry like so:

Depending on some factors that I'm not yet able to determine I either get

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

Or

I would like to run powershell script on multiple PCs (obviously using. Apr 21, 2018 - Does anybody know why this script is failing? I've tried to extend a script describing how to use PowerShell with the RegistryKey CLR class.

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 because the user I'm running the powershell script as doesn't have the appropriate credentials to access the remote registry. I'd like to be able to supply a set of credentials to use for the remote registry access, but I can find no documentation anywhere of a way to do this. I'm also not clear on exactly where to specify which users are allowed to access the registry remotely.

sgibbonssgibbons

7 Answers

Just thought I'd add my answer to anyone with this problem as well. It seems there is no way to add Credentials using RemoteRegistry. You can however use WMI to query a remote registry using alternative credentials as follows:

From here you can call standard Registry methods. The below example will return the operating system.

Hope this helps someone :)

Ben TaylorBen Taylor

Are you running remote registry service? It is disabled by default and that must be causing the issue. Check the status of this service on all remote machines you are trying to access.

ravikanthravikanth

I couldn't comment directly on bentaylr's entry above, but I've taken what he contributed and added PSCredentials creation (figured out from here) to allow you to hard code credentials into the script.

Peace of mind disclaimer: Be careful when using plaintext credentials in a script. In my case, I'm using generic credentials on machines I'm launching. Depending on your case, you might consider creating an encrypted credential file to store the password in (see link above).

The credentials you use would need to be able to access the registry if you were logged into that user on the machine you are targeting.

ddncnddncn

OverloadDefinitions

Powershell

try

HanselHansel

$key.OpenSubKey($subkeyName) opens the subkey in write protected mode,$key.OpenSubKey($subkeyName,$true) opens it in writable mode

Therefore after $key.OpenSubKey($subkeyName,$true) you should be able to create a new subkey or value

If you try the same thing after $key.OpenSubKey($subkeyName) you will get 'UnauthorizedAccessException'

Wolfgang KWolfgang K

Came looking for the answer to your question, but in a little googling this morning I noticed that the first parameter is a type rather than a String.. hope this helps:

pmorrisonflpmorrisonfl

I wanted to first thank all for answers above really helpful, wanted to add that you can use Get-Credential command to collect credentials without having to hard code it in your script. I have written using the above suggestions into my script the following code and query:

The above code returns all sub key names in the specified key so that I can determine installed updates other than OS which have been applied to a server. If you want to determine all collection possibilities with the $objReg variable then run:

You will see a list of all possible queries which can be performed against the registry. Hope this helps!

user5790768user5790768

Not the answer you're looking for? Browse other questions tagged powershellregistry.netpermissions or ask your own question.

-->

Definition

Opens a new T:Microsoft.Win32.RegistryKey that represents the requested key on a remote machine, with the option of specified registry view.

Overloads

OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)

Opens a new RegistryKey that represents the requested key on a remote machine.

OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Opens a new registry key that represents the requested key on a remote machine with the specified view.

OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)OpenRemoteBaseKey(RegistryHive, String)

Opens a new RegistryKey that represents the requested key on a remote machine.

Parameters

hKey
RegistryHiveRegistryHiveRegistryHiveRegistryHive

The HKEY to open, from the RegistryHive enumeration.

Apr 12, 2018 - Commandos: Behind Enemy Lines guide at StrategyWiki Commandos. This fix works on windows 10 for the GOG.com version. Jan 4, 2013 - I intended today to play the old Commandos Behind the Enemy Lines once again to remind my childhood days once again and downloaded it. Commandos behind enemy lines walkthrough. Dec 10, 2015 - Commandos: Behind Enemy Lines. All Discussions Screenshots. Windows 7 64 bit fix for nvidea card owners. Been trying to fix this for ages. Commandos: Behind Enemy Lines. Thing is that this game was running ok for me on win 7 x64 but after upgrade to win 10 nothing work, even this BEL patch.

machineName
StringStringStringString

The remote machine.

Returns

The requested registry key.

Exceptions

ArgumentExceptionArgumentExceptionArgumentExceptionArgumentException

hKey is invalid.

machineName is not found.

ArgumentNullExceptionArgumentNullExceptionArgumentNullExceptionArgumentNullException

machineName is null.

SecurityExceptionSecurityExceptionSecurityExceptionSecurityException

The user does not have the proper permissions to perform this operation.

Openremotebasekey

Openremotebasekey Powershell

UnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessException

The user does not have the necessary registry rights.

Examples

The following code example shows how to open a registry key on a remote computer and enumerate the values of the key. The remote computer must be running the remote registry service. Specify the name of the remote computer as a command-line argument when invoking the program.

Remarks

The local machine registry is opened if machineName is String.Empty. The requested key must be a root key on the remote machine, and is identified by the appropriate RegistryHive value.

In order for a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled.

Security

SecurityPermission
for the ability to access the specified registry key if it is a remote key. Associated enumeration: UnmanagedCode

See also
OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)

OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)OpenRemoteBaseKey(RegistryHive, String, RegistryView)

Opens a new registry key that represents the requested key on a remote machine with the specified view.

Parameters

hKey
RegistryHiveRegistryHiveRegistryHiveRegistryHive

The HKEY to open from the RegistryHive enumeration.

machineName
StringStringStringString

The remote machine.

view
RegistryViewRegistryViewRegistryViewRegistryView

The registry view to use.

Returns

The requested registry key.

Exceptions

ArgumentExceptionArgumentExceptionArgumentExceptionArgumentException

hKey or view is invalid.

machineName is not found.

ArgumentNullExceptionArgumentNullExceptionArgumentNullExceptionArgumentNullException

machineName is null.

UnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessException

The user does not have the necessary registry rights.

SecurityExceptionSecurityExceptionSecurityExceptionSecurityException

The user does not have the required permissions to perform this operation. Thinkfree office mobile pro apk download.

Remarks

The local machine registry is opened if machineName is String.Empty. The requested key must be a root key on the remote machine, and is identified by the appropriate RegistryHive value.

Powershell Microsoft.win32.registrykey Openremotebasekey Credentials

In order for a key to be opened remotely, both the server and client machines must be running the remote registry service, and have remote administration enabled.

On the 64-bit versions of Windows, portions of the registry are stored separately for 32-bit and 64-bit applications. There is a 32-bit view for 32-bit applications and a 64-bit view for 64-bit applications. If view is Registry64 but the remote machine is running a 32-bit operating system, the returned key will use the Registry32 view.

Applies to