This project is read-only.

Set-RegistryKey - wrong format

Topics: Archive - General
Nov 4, 2014 at 3:20 PM

I trying to set registry key using:

Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes\7-Zip.7z\DefaultIcon" -Name "(Default)" -Value "C:\Program Files\7-Zip\7z.dll,0" -Type String

but I got error:

Cannot process argument transformation parameter 'ContinueOnError'. Cannot convert value "System.string" to type "System.Boolen", parameters of this type only accept .....

Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\" -Name "(Default)" -Value "" -Type String

working OK.

What is correst syntax of Value - "C:\Program Files\7-Zip\7z.dll,0"


Nov 4, 2014 at 3:49 PM
Strange that argument transformation error is for ContinueOnError.

Does specifying single quote to specify string literal work?:
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\7-Zip.7z\DefaultIcon' -Name '(Default)' -Value 'C:\Program Files\7-Zip\7z.dll,0' -Type String
Marked as answer by rudok on 11/4/2014 at 8:32 AM
Nov 4, 2014 at 4:12 PM
No, I got different error:

Cannot process argument transformationon on parameter 'Type'. Cannot convert value "C:\Program" to type "Microsoft.Win32.RegistryValueKind" due to invalid enumeration values.

Nov 4, 2014 at 4:24 PM
Can you try by not specifying the -Type parameter as the default type is already String?
Nov 4, 2014 at 4:25 PM
or specify the Type parameter like so?:
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\7-Zip.7z\DefaultIcon' -Name '(Default)' -Value 'C:\Program Files\7-Zip\7z.dll,0' -Type [Microsoft.Win32.RegistryValueKind]'String'
Nov 4, 2014 at 4:33 PM
Sorry, I tested it again and your solution work for me.


Nov 4, 2014 at 4:34 PM
Which solution worked?
Nov 4, 2014 at 4:45 PM
Your first advice using ' instead ".


Thx again
Nov 4, 2014 at 4:51 PM
Edited Nov 4, 2014 at 4:52 PM
Cool, yw. Using " instead of ' interchangeably works in most cases but strange bugs can crop up sometimes if not being careful because PowerShell will always scan text inside " quotes to see if they can be interpreted in any way. Using ' string literals where you know it's just text avoids such issues. In some cases, using the two interchangeably can also open you to security vulnerabilities when accepting input from some source for execution.