Replacing registry default value from command line

5

1

I'm modifying an entry in the Windows registry. In the key there is a single value called (Default) of type REG_SZ. This value is not set.

I've tried using REG Add "HKEY_CURRENT_USER\SOFTWARE\Classes\.jpg" /f /v "(Default)" /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff" to change the data associated with (Default), but instead it creates a second (Default) value underneath the original, like so:

enter image description here

How can I correctly replace this information without using a reg file? I want to stick to the command line for the purposes of this project.

Forest

Posted 2016-03-22T09:51:58.023

Reputation: 193

Answers

4

How can I correctly replace this information

REG Add "HKEY_CURRENT_USER\SOFTWARE\Classes\.jpg" /f /v "(Default)" /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff"

Use the /ve option (Set the (default) value) instead of /v:

REG Add "HKEY_CURRENT_USER\SOFTWARE\Classes\.jpg" /ve /d "PhotoViewer.FileAssoc.Tiff" /f

Syntax

REG ADD [ROOT\]RegKey /ve [/d Data] [/f] -- Set the (default) value

Source reg


Further Reading

DavidPostill

Posted 2016-03-22T09:51:58.023

Reputation: 118 938

2

Try using /ve instead of /v like this: REG Add "HKEY_CURRENT_USER\SOFTWARE\Classes\.jpg" /f /ve /d "PhotoViewer.FileAssoc.Tiff"

duenni

Posted 2016-03-22T09:51:58.023

Reputation: 2 109

You don't need /t REG_SZ as the default value is already a string. – DavidPostill – 2016-03-22T10:00:36.667

You're right. Edited this. – duenni – 2016-03-22T10:02:48.947

1

Hint: /ve adds an empty value name (Default) for the key.

So the correct Command-line would be:

REG Add "HKEY_CURRENT_USER\SOFTWARE\Classes\.jpg" /f /ve /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff"

Or the shorter form.

REG Add "HKCU\SOFTWARE\Classes\.jpg" /f /ve /t REG_SZ /d "PhotoViewer.FileAssoc.Tiff"

w32sh

Posted 2016-03-22T09:51:58.023

Reputation: 8 611

You don't need /t REG_SZ as the default value is already a string. – DavidPostill – 2016-03-22T10:00:58.497

1Correct. But the force of habit. And I prefer to include it for the sake of uniformity. – w32sh – 2016-03-22T10:02:31.893