Is it possible to import registry entries directly from the output of another process (i.e. over a pipe from STDIN)?
I have some registry entries in a .reg file that I'd like to import, but only after making some on-the-fly modifications (filling in placeholder values like username, etc.). I was planning on using the methods from How can you find and replace text in a file using the Windows command-line environment? to do the modifications, but now I need to figure out how to get the modified version into the registry.
(gc foo.reg) -creplace '^"UserName"=""$', "`"UserName`"=`"$env:USERNAME`"" | | ...
I've been looking at the documentation for REG IMPORT
, which requires a filename as an arguments. In Unix shell-scripting, which I have much more experience in, there are a lot of ways to solve the problem. If we imagine a Unix version of the command reg -i
which requires a filename, some possible solutions would be
sed 's/bar/baz/' foo.reg|reg -i
or
sed 's/bar/baz/' foo.reg|reg -i -
or
sed 's/bar/baz/' foo.reg|reg -i /dev/stdin
or even
reg -i <(sed 's/bar/baz/' foo.reg)
(Only the first two are at all natural.)
Is there an equivalent for Windows?
Note that I'm fine with solutions in either CMD- or PowerShell-style scripting, if that makes a difference.