Command line registry edit

0

I seem to have a problem with a reg command that I'm trying to add by cmd. Any ideas how I can fix this syntax error, since the command dosent seem wrong...

reg add HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open\command /v command /t REG_MULTI_SZ /d xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ /dde /p "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" /e "%1"

I need to edit the command string and add the data:

xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ /dde /p "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" /e "%1"

Fate Averruncus

Posted 2015-01-21T16:09:39.750

Reputation: 42

What's the actual error message you receive when you try to run it? – Ƭᴇcʜιᴇ007 – 2015-01-21T16:24:52.623

What makes you believe the syntax is wrong? Why don't you just modify the registry, export the change, and run exported change instead of doing a command that might contain syntax problems? – Ramhound – 2015-01-21T16:25:16.310

Answers

2

Any ideas how I can fix this syntax error?

Your (binary?) string contains a > character (which is used to redirect the output from a command to a file).

You have:

REG_MULTI_SZ /d xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ 

Try using ":

REG_MULTI_SZ /d "xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ"

Or escaping the > with ^>:

REG_MULTI_SZ /d xb'BV5!!!!!!!!!MKKSkEXCELFiles^>VijqBof(Y8'w!FId1gLQ 

In addition your reg add ... command does not look correct.

You don't have an array of null-teminated strings that are terminated by two null characters.

Here is the correct syntax.

REG ADD [ROOT]RegKey /v ValueName [/t DataType] [/S Separator] [/d Data] [/f]

where:

/S Separator : Character to use as the separator in REG_MULTI_SZ values the default is "\0"

REG_MULTI_SZ Array of null-terminated strings that are terminated by two null characters.

Source REG.exe:

See https://stackoverflow.com/questions/8853911/reg-add-a-reg-multi-sz-multi-line-registry-value for more information


Syntax : Escape Characters, Delimiters and Quotes

Escape Character

^ Escape character.

Adding the escape character before a command symbol allows it to be treated as ordinary text.

When piping or redirecting any of these charcters you should prefix with the escape character: & \ < > ^ |

 e.g.  ^\  ^&  ^|  ^>  ^<  ^^

Source Syntax : Escape Characters, Delimiters and Quotes


Further Reading

DavidPostill

Posted 2015-01-21T16:09:39.750

Reputation: 118 938

If i change the data in any way for example if i add the " the application wont run and if i add the ^ i get a feature id not registred error need so somehow keep the data intact while adding it to the bat – Fate Averruncus – 2015-01-21T16:28:48.070

See updated answer. – DavidPostill – 2015-01-21T16:38:12.387

1

DavidPostil is right in that you have to enclose the entire data string in double quotes, and then escape and double quotes inside the string to ensure it knows they are part of the string.

In this case the entire data string you want to add is:

xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ /dde /p "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE" /e "%1"

So you want to wrap that entire string in double-quotes so that the command-line recognizes it as a single string (and not multiple arguments).

The trick is figuring out which quotes (and other characters) inside those delimiting quotes need to be escaped, and then figure out how to escape them for this context.

It took a little trial and error to figure it out, but for this case you only need to worry about the internal double-quotes, and you escape them by preceding them with a backslash (\):

reg add "HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open\command" /v command /t REG_MULTI_SZ /d "xb'BV5!!!!!!!!!MKKSkEXCELFiles>VijqBof(Y8'w!FId1gLQ /dde /p \"C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE\" /e \"%1\""

Having said all that, and based on the problems that seem to be continuing with nailing it down exactly, I think Ramhound might have mentioned the best/easiest solution in his comment.

Just go to a machine with the settings set as you'd like, then export that key to a .reg file.

Then use reg import in your batch file to import that .reg file.

If you don't like using/distributing two files, and/or you don't have a central place you could put it on the network, then you could always have the batch file create the .reg file on the fly by echoing the lines out to a temporary text file, import it and then delete the temp file once done.

Ƭᴇcʜιᴇ007

Posted 2015-01-21T16:09:39.750

Reputation: 103 763

Thanks for the help guys but i have tried that so it seems that it works to add it to a bat file but in the end the product dose not work it gets a error so is there any way to add more files a a bat or something like if i export that particular reg key and make it a pacake with the bat to run togheter or something? – Fate Averruncus – 2015-01-21T17:11:34.237

This solution looks good except that it is now not a REG_MULTI_SZ array of strings ... and I don't think it ever was even with the original code. – DavidPostill – 2015-01-21T17:48:14.313

@DavidPostill Good point. I just kind of assumed the data provided was correct. :) – Ƭᴇcʜιᴇ007 – 2015-01-21T18:03:14.553

Hmmmmm now other question if you dont mind, how to have the batch file create the .reg file by having the echoing lines into the text file? – Fate Averruncus – 2015-01-21T19:14:32.757

echo This is a line of text >> file.reg – Ƭᴇcʜιᴇ007 – 2015-01-21T20:07:37.450