5/21/2019
Posted by 
Powershell Microsoft.win32.registrykey Openremotebasekey Credentials Average ratng: 8,7/10 4123 reviews

Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to edit the registry on remote computers. Microsoft Scripting Guy, Ed Wilson, is here. In Wednesday’s PowerShell Essentials live meeting presentation, one of the questions revolved around working with the registry on. Jan 5, 2007 - Powershell, Remote Registry and You! Part 1 (Overview). I was reading the.

  1. Powershell Registry Opensubkey
  2. Openremotebasekey Powershell
-->

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.

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.

UnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessExceptionUnauthorizedAccessException

The user does not have the necessary registry rights.

Examples

Powershell Registry Opensubkey

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

Openremotebasekey Powershell

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
Powershell Microsoft.win32.registrykey Openremotebasekey Credentials

hKey or view is invalid.

machineName is not found.

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

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.

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

-->Powershell Microsoft.win32.registrykey Openremotebasekey Credentials

Definition

Represents a key-level node in the Windows registry. This class is a registry encapsulation.

Inheritance
MarshalByRefObjectMarshalByRefObjectMarshalByRefObjectMarshalByRefObject
RegistryKeyRegistryKeyRegistryKeyRegistryKey
Attributes
Implements
IDisposableIDisposableIDisposableIDisposable

Examples

The following code example shows how to create a subkey under HKEY_CURRENT_USER, manipulate its contents, and then delete the subkey.

Remarks

To get an instance of RegistryKey, use one of the static members of the Registry class.

The registry acts as a central repository of information for the operating system and the applications on a computer. The registry is organized in a hierarchical format, based on a logical ordering of the elements stored within it (please see Registry for the base-level items in this hierarchy). When storing information in the registry, select the appropriate location based on the type of information being stored. Be sure to avoid destroying information created by other applications, because this can cause those applications to exhibit unexpected behavior, and can also have an adverse effect upon your own application.

Important

This type implements the IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its Dispose method in a try/catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the 'Using an Object that Implements IDisposable' section in the IDisposable interface topic.

Registry keys are the base unit of organization in the registry, and can be compared to folders in File Explorer. A particular key can have subkeys, just as a folder can have subfolders. Each key can be deleted, as long as the user has the appropriate permissions to do so, and the key is not a base key or at the level directly under the base keys. Each key can also have multiple values associated with it (a value can be compared to a file), which are used to store the information - for example, information about an application installed on the computer. Each value holds one particular piece of information, which can be retrieved or updated when required. For instance, you can create a RegistryKey for your company, under the key HKEY_LOCAL_MACHINESoftware, and then a subkey for each application that your company creates. Each subkey holds the information specific to that application, such as color settings, screen location and size, or recognized file extensions.

Note that information stored in the registry is available to other applications and users, and therefore should not be used to store security data or critical application information.

Caution

Do not expose RegistryKey objects in such a way that a malicious program could create thousands of meaningless subkeys or key/value pairs. For example, do not allow callers to enter arbitrary keys or values.

Starting in the .NET Framework 4, the length of a registry key is no longer limited to 255 characters.

Properties

HandleHandleHandleHandle

Gets a SafeRegistryHandle object that represents the registry key that the current RegistryKey object encapsulates.

NameNameNameName

Retrieves the name of the key.

SubKeyCountSubKeyCountSubKeyCountSubKeyCount

Retrieves the count of subkeys of the current key.

ValueCountValueCountValueCountValueCount

Retrieves the count of values in the key.

ViewViewViewView

Gets the view that was used to create the registry key.

Methods

Close()Close()Close()Close()

Closes the key and flushes it to disk if its contents have been modified.

CreateObjRef(Type)CreateObjRef(Type)CreateObjRef(Type)CreateObjRef(Type)

Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
CreateSubKey(String)CreateSubKey(String)CreateSubKey(String)CreateSubKey(String)

Creates a new subkey or opens an existing subkey for write access.

CreateSubKey(String, Boolean)CreateSubKey(String, Boolean)CreateSubKey(String, Boolean)CreateSubKey(String, Boolean)

Creates a new subkey or opens an existing subkey with the specified access. Available starting with .NET Framework 4.6.

CreateSubKey(String, Boolean, RegistryOptions)CreateSubKey(String, Boolean, RegistryOptions)CreateSubKey(String, Boolean, RegistryOptions)CreateSubKey(String, Boolean, RegistryOptions)

Creates a new subkey or opens an existing subkey with the specified access. Available starting with .NET Framework 4.6.

CreateSubKey(String, RegistryKeyPermissionCheck)CreateSubKey(String, RegistryKeyPermissionCheck)CreateSubKey(String, RegistryKeyPermissionCheck)CreateSubKey(String, RegistryKeyPermissionCheck)

Creates a new subkey or opens an existing subkey for write access, using the specified permission check option.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)

Creates a subkey or opens a subkey for write access, using the specified permission check and registry options.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)

Creates a subkey or opens a subkey for write access, using the specified permission check option, registry option, and registry security.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)

Creates a new subkey or opens an existing subkey for write access, using the specified permission check option and registry security.

DeleteSubKey(String)DeleteSubKey(String)DeleteSubKey(String)DeleteSubKey(String)

Deletes the specified subkey.

DeleteSubKey(String, Boolean)DeleteSubKey(String, Boolean)DeleteSubKey(String, Boolean)DeleteSubKey(String, Boolean)

Deletes the specified subkey, and specifies whether an exception is raised if the subkey is not found.

DeleteSubKeyTree(String)DeleteSubKeyTree(String)DeleteSubKeyTree(String)DeleteSubKeyTree(String)

Deletes a subkey and any child subkeys recursively.

DeleteSubKeyTree(String, Boolean)DeleteSubKeyTree(String, Boolean)DeleteSubKeyTree(String, Boolean)DeleteSubKeyTree(String, Boolean)

Deletes the specified subkey and any child subkeys recursively, and specifies whether an exception is raised if the subkey is not found.

DeleteValue(String)DeleteValue(String)DeleteValue(String)DeleteValue(String)

Deletes the specified value from this key.

DeleteValue(String, Boolean)DeleteValue(String, Boolean)DeleteValue(String, Boolean)DeleteValue(String, Boolean)

Deletes the specified value from this key, and specifies whether an exception is raised if the value is not found.

Dispose()Dispose()Dispose()Dispose()

Releases all resources used by the current instance of the RegistryKey class.

Equals(Object)Equals(Object)Equals(Object)Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()Finalize()Finalize()Finalize()

Closes the key and flushes it to disk if the contents have been modified.

Flush()Flush()Flush()Flush()

Writes all the attributes of the specified open registry key into the registry.

FromHandle(SafeRegistryHandle)FromHandle(SafeRegistryHandle)FromHandle(SafeRegistryHandle)FromHandle(SafeRegistryHandle)

Creates a registry key from a specified handle.

FromHandle(SafeRegistryHandle, RegistryView)FromHandle(SafeRegistryHandle, RegistryView)FromHandle(SafeRegistryHandle, RegistryView)FromHandle(SafeRegistryHandle, RegistryView)

Creates a registry key from a specified handle and registry view setting.

GetAccessControl()GetAccessControl()GetAccessControl()GetAccessControl()

Returns the access control security for the current registry key.

GetAccessControl(AccessControlSections)GetAccessControl(AccessControlSections)GetAccessControl(AccessControlSections)GetAccessControl(AccessControlSections)

Returns the specified sections of the access control security for the current registry key.

GetHashCode()GetHashCode()GetHashCode()GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()GetLifetimeService()GetLifetimeService()GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSubKeyNames()GetSubKeyNames()GetSubKeyNames()GetSubKeyNames()

Retrieves an array of strings that contains all the subkey names.

GetType()GetType()GetType()GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(String)GetValue(String)GetValue(String)GetValue(String)

Retrieves the value associated with the specified name. Returns null if the name/value pair does not exist in the registry.

GetValue(String, Object)GetValue(String, Object)GetValue(String, Object)GetValue(String, Object)

Retrieves the value associated with the specified name. If the name is not found, returns the default value that you provide.

GetValue(String, Object, RegistryValueOptions)GetValue(String, Object, RegistryValueOptions)GetValue(String, Object, RegistryValueOptions)GetValue(String, Object, RegistryValueOptions)

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

GetValueKind(String)GetValueKind(String)GetValueKind(String)GetValueKind(String)

Retrieves the registry data type of the value associated with the specified name.

GetValueNames()GetValueNames()GetValueNames()GetValueNames()

Retrieves an array of strings that contains all the value names associated with this key.

InitializeLifetimeService()InitializeLifetimeService()InitializeLifetimeService()InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()MemberwiseClone()MemberwiseClone()MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)MemberwiseClone(Boolean)MemberwiseClone(Boolean)MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OpenBaseKey(RegistryHive, RegistryView)OpenBaseKey(RegistryHive, RegistryView)OpenBaseKey(RegistryHive, RegistryView)OpenBaseKey(RegistryHive, RegistryView)

Opens a new RegistryKey that represents the requested key on the local 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.

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.

OpenSubKey(String)OpenSubKey(String)OpenSubKey(String)OpenSubKey(String)

Retrieves a subkey as read-only.

OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)OpenSubKey(String, Boolean)

Retrieves a specified subkey, and specifies whether write access is to be applied to the key.

OpenSubKey(String, RegistryKeyPermissionCheck)OpenSubKey(String, RegistryKeyPermissionCheck)OpenSubKey(String, RegistryKeyPermissionCheck)OpenSubKey(String, RegistryKeyPermissionCheck)

Retrieves the specified subkey for read or read/write access.

OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)

Retrieves the specified subkey for read or read/write access, requesting the specified access rights.

OpenSubKey(String, RegistryRights)OpenSubKey(String, RegistryRights)OpenSubKey(String, RegistryRights)OpenSubKey(String, RegistryRights)

Retrieves a subkey with the specified name and access rights. Available starting with .NET Framework 4.6.

SetAccessControl(RegistrySecurity)SetAccessControl(RegistrySecurity)SetAccessControl(RegistrySecurity)SetAccessControl(RegistrySecurity)

Applies Windows access control security to an existing registry key.

SetValue(String, Object)SetValue(String, Object)SetValue(String, Object)SetValue(String, Object)

Sets the specified name/value pair.

SetValue(String, Object, RegistryValueKind)SetValue(String, Object, RegistryValueKind)SetValue(String, Object, RegistryValueKind)SetValue(String, Object, RegistryValueKind)

Sets the value of a name/value pair in the registry key, using the specified registry data type.

ToString()ToString()ToString()ToString()

Retrieves a string representation of this key.

Explicit Interface Implementations

IDisposable.Dispose()IDisposable.Dispose()IDisposable.Dispose()IDisposable.Dispose()

Performs a Close() on the current key.

Extension Methods

GetAccessControl(RegistryKey)GetAccessControl(RegistryKey)GetAccessControl(RegistryKey)GetAccessControl(RegistryKey)
GetAccessControl(RegistryKey, AccessControlSections)GetAccessControl(RegistryKey, AccessControlSections)GetAccessControl(RegistryKey, AccessControlSections)GetAccessControl(RegistryKey, AccessControlSections)
SetAccessControl(RegistryKey, RegistrySecurity)SetAccessControl(RegistryKey, RegistrySecurity)SetAccessControl(RegistryKey, RegistrySecurity)SetAccessControl(RegistryKey, RegistrySecurity)

Applies to

See also

  • RegistryHiveRegistryHiveRegistryHiveRegistryHive