Set-RegistryKey - wrong format

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

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

command:
Set-RegistryKey -Key "HKEY_LOCAL_MACHINE\SOFTWARE\Classes.zip" -Name "(Default)" -Value "7-Zip.zip" -Type String

working OK.

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

Thx

Rudolf
Developer
Nov 4, 2014 at 2: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 3: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.

Rudolf
Developer
Nov 4, 2014 at 3:24 PM
Can you try by not specifying the -Type parameter as the default type is already String?
Developer
Nov 4, 2014 at 3: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 3:33 PM
Sorry, I tested it again and your solution work for me.

Thx

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

Rudo

Thx again
Developer
Nov 4, 2014 at 3:51 PM
Edited Nov 4, 2014 at 3: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.