mikesw Posted December 11, 2007 Share Posted December 11, 2007 I'm trying to use a batch comand along with the reg.exe command and I want toconcatenate two strings together to make up the complete registry key, andone 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.execomplains that the key is either not found or illegal. The same for single quotesset key=SYSTEM\CurrentControlSet\Control\Terminal Serverreg query HKLM\%key% /v TSAdvertiseThe above command doesn't work unless I put the "HKLM\" in the line before SYSTEM anddouble 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 thatit 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 batchfile which then is merged with the registry key and then executed by the reg.exe commandso that I can change the registry remotely on any computer in my local home subnet. Whatif the computername is a domain name how would this be done too? Link to comment Share on other sites More sharing options...
Mijzelf Posted December 11, 2007 Share Posted December 11, 2007 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 TSAdvertiseNow 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 Serverand the command line becomes:reg query "HKLM\%key%" /v TSAdvertiseor two variabelesset key1=SYSTEM\CurrentControlSetset key2=\Control\Terminal Serverreg query "HKLM\%key1%%key2%" /v TSAdvertiseBTW, how do I pass an argument on the command line when I execute the batch file so thatit 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 TSAdvertiseand call it withDoReg.cmd SYSTEM\CurrentControlSet "\Control\Terminal Server" Link to comment Share on other sites More sharing options...
mikesw Posted December 11, 2007 Author Share Posted December 11, 2007 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 Serverand the command line becomes:reg query "HKLM\%key%" /v TSAdvertiseThanks, your stuff works. I was trying to put double quotes around the string after the equals sign alongwith what you did for the "reg query" one and it had problems. The reason is that in some computerlanaguages "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 quotefor a string? This didn't work for me either. Link to comment Share on other sites More sharing options...
mikesw Posted December 12, 2007 Author Share Posted December 12, 2007 Another problem I'm running into which the windows help doesn't show is the handling ofnull 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 isneeded besides an empty string? Link to comment Share on other sites More sharing options...
Mijzelf Posted December 12, 2007 Share Posted December 12, 2007 if "%1" == "" echo string is emptyThis is a great site about batch files and their usage. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now