Jump to content

Howto concatenate strings in the reg.exe command?


mikesw

Recommended Posts

I'm trying to use a batch comand along with the reg.exe command and I want to

concatenate two strings together to make up the complete registry key, and

one or both of the strings contains spaces in the key name. However, when I

try to specify double quotes around the string containing the space, reg.exe

complains that the key is either not found or illegal. The same for single quotes

set key=SYSTEM\CurrentControlSet\Control\Terminal Server

reg query HKLM\%key% /v TSAdvertise

The above command doesn't work unless I put the "HKLM\" in the line before SYSTEM and

double quote the full string. How can I do it by splitting into two different strings?

Moreover, when do I use

a). %%key%%

b ). %"%key%"%

or some other variation of the above.....

BTW, how do I pass an argument on the command line when I execute the batch file so that

it gets substituted into the batch variable to be used in the registry key concatenation?

The reason is because I want to pass the computer name in the command line of the batch

file which then is merged with the registry key and then executed by the reg.exe command

so that I can change the registry remotely on any computer in my local home subnet. What

if the computername is a domain name how would this be done too?

:blink:

Link to comment
Share on other sites


reg is a commandline program here, so the parameters are devided by spaces. In your case one of the parameters contain a space, so you'll have to use double quotes. The command line should be

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v TSAdvertise

Now you're using a variabele, which you fill with 'set'. In this case the spaces automatically are added, so the line is:

set key=SYSTEM\CurrentControlSet\Control\Terminal Server

and the command line becomes:

reg query "HKLM\%key%" /v TSAdvertise

or two variabeles

set key1=SYSTEM\CurrentControlSet

set key2=\Control\Terminal Server

reg query "HKLM\%key1%%key2%" /v TSAdvertise

BTW, how do I pass an argument on the command line when I execute the batch file so that

it gets substituted into the batch variable to be used in the registry key concatenation?

The commandline arguments added to a batchfile are called %1 %2 %3 ...

So you could write

reg query "HKLM\%1%2" /v TSAdvertise

and call it with

DoReg.cmd SYSTEM\CurrentControlSet "\Control\Terminal Server"

Link to comment
Share on other sites

reg is a commandline program here, so the parameters are devided by spaces. In your case one of the parameters contain a space, so you'll have to use double quotes. The command line should be

set key=SYSTEM\CurrentControlSet\Control\Terminal Server

and the command line becomes:

reg query "HKLM\%key%" /v TSAdvertise

Thanks, your stuff works. I was trying to put double quotes around the string after the equals sign along

with what you did for the "reg query" one and it had problems. The reason is that in some computer

lanaguages "a""b" is the concatenation method, but in batch shell scripts it isn't.

Is there any case whereby one has to delimit as \"b\" by using a back-slash followed by a double quote

for a string? This didn't work for me either.

Link to comment
Share on other sites

Another problem I'm running into which the windows help doesn't show is the handling of

null strings. when I do the following, the script complains in the if statement.

set null=

if %1 EQU %null% echo "string is empty" else echo "string is %1"

If I replace the %null% with "" , it doesn't like this either.

How does one test for null/empty strings so that I can tell the user that something is

needed besides an empty string?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...