Batch file that create another batch file

June 15, 2010 at 14:38:44
Specs: Windows XP
Trying to create a batch file that will create a new batch file on the desktop. Sound easy enough? This is what I have so far:

echo THIS IS A TEST > "%USERPROFILE%\Desktop\test.bat"
type %USERPROFILE%\Desktop\test.bat > %var1%


Tbe above created the new file fine and inputs the text, however I need to add multiple lines of text to the new batch file and can't figure this out.
Thanks in advance.


See More: Batch file that create another batch file

Report •


#1
June 15, 2010 at 15:07:29
@echo off & setLocal enableDELAYedeXpansion

pushd "%USERPROFILE%\Desktop"

(
echo @echo off
echo line one
echo line two
) > test.bat


=====================================
Helping others achieve escape felicity

M2


Report •

#2
June 15, 2010 at 15:26:28
The following command appends insted of overrights...

type %USERPROFILE%\Desktop\test.bat >> %var1%

not the two >> chevrons.

But why not modify you code to...

echo THIS IS A TEST >> "%USERPROFILE%\Desktop\"%var1%


Report •

#3
June 15, 2010 at 15:33:40
Sure, but what is %var1% supposed to be?


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
June 15, 2010 at 16:47:21
True but only the OP know because we can't see the whole code. We don't know what he is even doing because he did not say. Would be nice to know because I am betting there is a way better way.

Report •

#5
June 16, 2010 at 07:16:54
Thanks for the help thus far. What i'm trying to do is when a bat file is downloaded/ran, it creates a new bat file on the users desktop. Also in the script I would like to know if its possible a sceduled task to be created to run the new file that has been placed on the desktop? Here is all my script:

pushd "%USERPROFILE%\Desktop"

(
echo Net use lpt1: \\%logonserver%\printer /persistent:yes
echo O:
echo Cd\folder
echo runme o:\folder\ *.ocl
echo If exist o:\ocl (
echo Echo
echo ) else (
echo Md o:\ocl
echo )
echo Move c:\folder\*.ocl c:\ocl
) > test.bat

schtasks /create /TN "Printing" /TR "%USERPROFILE%\Desktop\test.bat" /SC DAILY /ST 12:00:00

The script is not running, its erroring out where the 'else' is on the text that should be inserted into the new bat file.

THANKS AGAIN!


Report •

#6
June 16, 2010 at 18:17:51
This makes no sence. Is this a Windows Server Network? If so why not just run a batch file that copies a shortcut to the desktop that would run the batch file from your server and then assign it to the login script under the users GPO?

Report •

#7
November 20, 2010 at 02:57:22
I'm having the same problem. For some reason, in my script, the only way to get echo to copy the command lines to a new .bat file I have to put them in quotes. But then they are useless because they have quotes around them.

(
echo @echo off
echo cd C:\Program Files (x86)\Ubisoft\Ghost Recon Advanced Warfighter
echo del context_bp_weapons_pack_v6.0.xml
echo rd /s /q local\bp_weapons_pack_v6.0
echo pause
) > "%~dp0"\uninstall.bat


Report •

#8
November 20, 2010 at 15:39:30
The closing bracket ")" in the echo commands gets mistaken for a closing bracket matching the batch file's earlier opening bracket. You need to escape it with a caret:

^)


Report •

#9
December 8, 2010 at 14:18:00
i found that this works quite well and it is only one line.

echo Hello world! >> "(name of new file).bat"

this works if you place the batch file on the desktop.
if you dont, it will create the file at the location of the original batach file.
hope this helps.


Report •

#10
December 8, 2010 at 15:09:42
Yep... and the new bat is useless.


=====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question