Computing.Net > Forums > Programming > Batch file adding text to file also

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file adding text to file also

Reply to Message Icon

Name: ediblespread
Date: July 30, 2008 at 08:50:54 Pacific
OS: XP
CPU/Ram: N/A
Product: N/A
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: July 30, 2008 at 10:16:24 Pacific
Reply:

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?


0

Response Number 2
Name: ediblespread
Date: July 30, 2008 at 11:28:11 Pacific
Reply:

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


0

Response Number 3
Name: ediblespread
Date: July 30, 2008 at 11:54:25 Pacific
Reply:

*Cries*

It works. It works at home.

Why doesn't it work at work then! Argh!

-Edibles


0

Response Number 4
Name: Mechanix2Go
Date: July 30, 2008 at 15:09:59 Pacific
Reply:

:: append some str to reg.txt all on one line

@echo off > newfile
setLocal EnableDelayedExpansion

set /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


0

Response Number 5
Name: ediblespread
Date: July 31, 2008 at 01:22:06 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: klint
Date: July 31, 2008 at 02:40:53 Pacific
Reply:

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


0

Response Number 7
Name: ediblespread
Date: July 31, 2008 at 03:00:06 Pacific
Reply:

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.


0

Response Number 8
Name: ediblespread
Date: August 1, 2008 at 02:49:54 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch file adding text to file also

echo text to specific line in file www.computing.net/answers/programming/echo-text-to-specific-line-in-file/11965.html

Adding Text To Lines In File www.computing.net/answers/programming/adding-text-to-lines-in-file/9176.html

Adding text to a static box in c++ www.computing.net/answers/programming/adding-text-to-a-static-box-in-c/4941.html