goudeuk wrote:Code: Select all
set name=%hostname% | reg add "HKCU\Software\BBWin\hostname" /f /v "%name%.domain.co.uk" /t REG_SZ /d "Yes"
. . .
I would appreciate it, if you could tell me how a pipe is intended to be used.
A pipe is used to feed a data that is usually read
via the keyboard. For example, this test.bat Batch file:
Code: Select all
@echo off
set /P "var="
echo Value read: %var%
... read the value of "var" variable from the keyboard, so you may give such value via a pipe this way:
The REG command does NOT read a data
via the keyboard, so the pipe is not useful in this case.
Even if REG command would read a data via the keyboard, the command placed at left side of the pipe should be ECHO, because SET command does NOT send any output to the screen.
-------------------------------------
The way to execute two commands in the same line is separating they with an ampersand, like this:
However, if the first command is a SET and you want to use the just assigned value in the second command, then there are problems related to delayed expansion. There are two ways to achieve this at the command-prompt; using delayed expansion:
Code: Select all
cmd /V:ON /C set "name=%hostname%" ^& reg add "HKCU\Software\BBWin\hostname" /f /v "!name!.domain.co.uk" /t REG_SZ /d "Yes"
... or using the CALL trick:
Code: Select all
set "name=%hostname%" & CALL reg add "HKCU\Software\BBWin\hostname" /f /v "%name%.domain.co.uk" /t REG_SZ /d "Yes"
For further explanations of this point, search for "delayed expansion".
-------------------------------------
However, all this stuff is absolutely unnecessary! Answer this: if you want add the value of A to X, what do you do: "SET /A X=X+A" or "SET B=%A% & SET /A X=X+B"? Why define B variable with the value of A when the value of A can be directly used? Well, just use the same reasoning in your problem (as Squashman indicated in his reply):
Code: Select all
reg add "HKCU\Software\BBWin\hostname" /f /v "%hostname%.domain.co.uk" /t REG_SZ /d "Yes"