Weird batch error when working with reg.exe

Hello,

basically I am having a weird issue when I try to use a batch file to pull a bit of text from a text file - I try and turn it into a variable and then write that variable to the value of a registry key. It's fairly straight forward but when I execute the file, the reg part completely ignores the variable (the key ends up having /f in it, instead of what I want). See below.

@echo off
SETLOCAL EnableDelayedExpansion
for /F "delims=" %%i in (C:\temp\output.txt) do set "wowvar=%%i"
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom1 /t REG_SZ /d %xwowvar% /f

Open in new window


and when it's done, I get the following output...

C:\Temp1>for /F "delims=" %i in (C:\temp\output.txt) do set "wowvar=%i"

C:\Temp1>REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom1 /t REG_SZ /d
  /f
The operation completed successfully.

Open in new window


(Output.txt only has about 8 characters in it, it's just a date, it's always 100% there)

Any help would be greatly appreciated.
LVL 1
HCommsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
Because it's xwowvar, not wowvar
HCommsAuthor Commented:
Apologies, that must have been when I was putting it in here - it made no difference.

C:\Temp1>for /F "delims=" %i in (C:\temp\output.txt) do set "wowvar=%i"

C:\Temp1>REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom1 /t REG_SZ /d
  /f
The operation completed successfully.

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
Can you upload your TXT file here, the exact one you are using?

I suspect it may not have normal Windows end of line (EOL) syntax, and may have either just a single carriage return, or a single line feed at the end of a line.

~bp
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

HCommsAuthor Commented:
See attached.
output.txt
Bill PrewIT / Software Engineering ConsultantCommented:
Ah, that's a unicode file, so you can try this.

@echo off
SETLOCAL EnableDelayedExpansion
for /F "delims=" %%i in ('type C:\temp\output.txt') do set "wowvar=%%i"
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\CentraStage /v Custom1 /t REG_SZ /d %wowvar% /f

Open in new window


~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
Also, be aware you have some trailing spaces on that line, but that may or may not be a problem.

~bp
HCommsAuthor Commented:
Ideal! That worked exactly as I wanted it!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.