Powershell Microsoft.win32.registrykey Openremotebasekey Credentials
Dec 10, 2014 Remote Printers In Powershell Welcome › Forums › General PowerShell Q&A › Remote Printers In Powershell This topic has 2 replies, 2 voices, and was last updated 5 years, 4 months ago.
-->Definition
Sets the value of a name/value pair in the registry key. Depending on the overload, the registry data type is determined from the type of data being stored or from a specified RegistryValueKind.
Overloads
SetValue(String, Object) | Sets the specified name/value pair. |
SetValue(String, Object, RegistryValueKind) | Sets the value of a name/value pair in the registry key, using the specified registry data type. |
Parameters
- name
- String
The name of the value to store.
Exceptions
value
is null
.
value
is an unsupported data type. The office season 6 episode 23.
The RegistryKey that contains the specified value is closed (closed keys cannot be accessed).
The RegistryKey is read-only, and cannot be written to; for example, the key has not been opened with write access.
-or-
The RegistryKey object represents a root-level node, and the operating system is Windows Millennium Edition or Windows 98.
The user does not have the permissions required to create or modify registry keys.
The RegistryKey object represents a root-level node, and the operating system is Windows 2000, Windows XP, or Windows Server 2003.
Examples
The following code example shows how the SetValue method determines the registry data type when it sets values. The example creates a test key and adds values of different data types to the key. The example then reads the name/value pairs and displays them to the console, using the GetValueKind method to display the corresponding registry data types.
Remarks
Because many values can be stored in each key in the registry, you must use the name
parameter to specify the particular value you want to set.
Note
A registry key can have one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string '(Default)' appears instead of a name. To set this unnamed value, specify either null
or the empty string (') for name
.
In order to set values in a key, you must open the key with write access. After you have opened a key with write access, you can change any of the name/value pairs in that key.
If the specified name
does not exist in the key, it is created and the associated value is set to value
.
This overload of SetValue stores 64-bit integers as strings (RegistryValueKind.String). To store 64-bit numbers as RegistryValueKind.QWord values, use the SetValue(String, Object, RegistryValueKind) overload that specifies RegistryValueKind.
This overload of SetValue stores all string values as RegistryValueKind.String, even if they contain expandable references to environment variables. To save string values as expandable strings (RegistryValueKind.ExpandString), use the SetValue(String, Object, RegistryValueKind) overload that specifies RegistryValueKind.
Numeric types other than 32-bit integers are stored as strings by this method overload. Enumeration elements are stored as strings containing the element names.
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.
Note
On Windows 98 and Windows Millennium Edition the registry is not Unicode, and not all Unicode characters are valid for all code pages. A Unicode character that is invalid for the current code page is replaced by the best available match. No exception is thrown.
See also
Sets the value of a name/value pair in the registry key, using the specified registry data type.
Parameters
- value
- Object
The data to be stored.
- valueKind
- RegistryValueKind
The registry data type to use when storing the data.
- Attributes
Exceptions
value
is null
.
The type of value
did not match the registry data type specified by valueKind
, therefore the data could not be converted properly.
The RegistryKey that contains the specified value is closed (closed keys cannot be accessed).
The RegistryKey is read-only, and cannot be written to; for example, the key has not been opened with write access.
-or-
The RegistryKey object represents a root-level node, and the operating system is Windows Millennium Edition or Windows 98.
The user does not have the permissions required to create or modify registry keys.
The RegistryKey object represents a root-level node, and the operating system is Windows 2000, Windows XP, or Windows Server 2003.
Examples
The following code example creates a test key and uses the SetValue method to store several values, specifying the registry data type for each value. The example then reads the name/value pairs and displays them to the console, using the GetValueKind method to display the corresponding registry data types.
Remarks
Because many values can be stored in each key in the registry, you must use the name
parameter to specify the particular value you want to set.
Note
A registry key can have one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string '(Default)' appears instead of a name. To set this unnamed value, specify either null
or the empty string (') for name
.
In order to set values in a key, you must open the key with write access. After you have opened a key with write access, you can change any of the name/value pairs in that key.
If the specified name
does not exist in the key, it is created, and the associated value is set to value
.
Note
Specifying the registry data type Unknown is the same as using the SetValue overload.
If the type of the specified value
does not match the specified valueKind
, and the data cannot be converted, ArgumentException is thrown. For example, you can store a System.Int64 as a RegistryValueKind.DWord, but only if its value is less than the maximum value of a System.Int32. You cannot store a single string value as a RegistryValueKind.MultiString.
Note
If boxed values are passed for RegistryValueKind.DWord or RegistryValueKind.QWord, the conversion is done using the invariant culture.
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.
Note
On Windows 98 and Windows Millennium Edition the registry is not Unicode, and not all Unicode characters are valid for all code pages. A Unicode character that is invalid for the current code page is replaced by the best available match. No exception is thrown.
See also
Applies to
- суббота 04 апреля
- 94