Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Batch file adding text to file also adds a return?
(Damn 35 character subject limits ;))
Hi there. Working on a very simple batch file; all it does is add a single sentence to a text file, then convert it to a .reg file. It has to be a single line, no more, or the reg file will not run. The text file before batching reads:
"Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Today]
"The batch file adds in the new value to be added to the key. However, once it's added in the text, it automatically adds a return after it... which breaks the .reg file (god, reg files are PICKY XD).
Anyway, is there anyway to either stop it adding that bloody return, or to backspace once and delete the return after the text is added?
Please help!
-Edibles
PS: Sorry, this is the batch:
cd %appdata%\Microsoft\Outlook
echo "Url"="C:\\Documents and Settings\\%username%\\Application Data\\Microsoft\\Outlook\\outlooktoday.html" >>registry.txt
copy registry.txt registry.reg /Y
regedit /s registry.reg
pause

When I tried your code, it worked just fine. I mean it did create a newline after the line, but regedit had no problem with it. What problem are you having?

That's weird.
There is no problem as per see, whether you run the 'broken' reg file, or if you take out the last line, they both claim to work fine. However, while the 'broken' one says the registry is changed, nothing changes.
I'm gonna try quickly from home, see if perhaps it's something work related. Or maybe it's just cause I've spent about 3 hours screwing around with a single registry and the computer's getting pissy ;)
-Edibles

:: append some str to reg.txt all on one line@echo off > newfile
setLocal EnableDelayedExpansionset /p regtxt=<reg.txt
echo !regtxt! "Url"="C:\\Documents and Settings\\%username%\\Application Data\\Microsoft\\Outlook\\outlooktoday.html" > registry.txt
copy registry.txt registry.reg /Y
=====================================
If at first you don't succeed, you're about average.M2

Interesting. Back at work, trying it again. I run the batch. Nothing happens. Randomly, I double click the reg file and choose yes. It works.
What the heck? I've now edited the batch file so that it merely runs registry.reg instead of regedit-ing it, but this means I can't automatically choose yes, which slows the process down for people (it runs every time at startup, as it's part of another batch file for updating something... unless, is there a way to only ever run the registry-writing line once? But remember the location may have to change, so it would have to be re-activated, and I won't be with this company for more than a month, nevermind however long they use my work for XD)
Mechanix2Go: Your file seems to output exactly the same .reg file as mine, except that I had to append "echo !regtxt! "Url"="C:\\Documents and Settings\\%username%\\Application Data\\Microsoft\\Outlook\\outlooktoday.html" > registry.txt" to have a double ">>" otherwise it overwrote everything in the text file. Weird. Doesn't work with regedit either.

Could it be some group policy that your network system administrators have added to the system that resets this registry value?
By the way, although it won't solve this problem, but just for future reference, the way to output a line to a file without appending a newline is this:
set /p =This line doesn't end with CR/LF.<nul>file.txt

You could be right there. The regedit command doesn't work with even a 'fixed' batch file (ironic that I never tried that? ^^). Could be a network restriction, odd though that they didnt block just running .reg files XD.
Anyway, we've sorta sorted it; there are 2 different batch files, once for install and one for updating. We'll stick it in the updating one for a few days, then move it to the install one to catch new people; this way people don't get the damn popup everytime they update. Plus, the registry only needs updated once anyway.
Thanks for all the help.

Hehe, you gotta love projects like these. (this isn't another 'help' post btw, it's a slight gloating/amusement post :P)
Original batch files; 5 lines each. Current batch files: 60 lines each. XD
Only 30 or so lines of coding of course; we're required to extensively comment this so that we can pass on these files to our network guys so they know what we're mess- what we're doing ^^.
-Edibles

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |