Page 1 of 1

Problem when creating batch file with batch file

Posted: 21 Jun 2014 09:48
by john924xps
Hi! In this piece of code, I'm trying to get the program to create an entirely new program, using the >> to put lines of code into a separate file. I've escaped all of the characters I thought necessary, but if you check it out yourself, the second half of the new code appears very messy. Could any of you help and tell me what's wrong?

Much appreciated!

Code: Select all

@echo off
title The Vault
color 0d

::initialization
if not exist "lckr0" md "lckr0"
if not exist "lckr0\passref.bat" goto :passref_creation
pause


:passref_creation
   (
      echo @echo off
      echo setlocal EnableDelayedExpansion
      echo title Enter Password...
      echo color 0b
      echo mode con: cols=50 lines=5
      echo set "chars= abcdefghijklmnopqrstuvwxyz1234567890"
      echo set "password="
      echo set "asterix="
      echo.
      echo :main
      echo cls
      echo echo Password: ^%password^%
      echo choice /c ^%chars: =^% /n /m "Password: ^%asterix^%"
      echo set password=^%password^%^!chars:~^%errorlevel^%,1^!
      echo set asterix=^%asterix^%*
      echo goto :main
   ) >> "lckr0\passref.bat"

Re: Problem when creating batch file with batch file

Posted: 21 Jun 2014 10:10
by npocmaka_

Code: Select all

@echo off
title The Vault
color 0d

::initialization
if not exist "lckr0" md "lckr0"
if not exist "lckr0\passref.bat" goto :passref_creation
pause


:passref_creation
   (
      echo @echo off
      echo setlocal EnableDelayedExpansion
      echo title Enter Password...
      echo color 0b
      echo mode con: cols=50 lines=5
      echo set "chars= abcdefghijklmnopqrstuvwxyz1234567890"
      echo set "password="
      echo set "asterix="
      echo.
      echo :main
      echo cls
      echo echo Password: %%password%%
      echo choice /c %%chars: =%% /n /m "Password: %%asterix%%"
      echo set password=%%password%%!chars:~%%errorlevel%%,1!
      echo set asterix=%%asterix%%*
      echo goto :main
   ) >> "lckr0\passref.bat"


?

Re: Problem when creating batch file with batch file

Posted: 23 Jun 2014 08:48
by john924xps
Ah whoops. I placed double percentages for some odd reason. It's supposed to be carets, but even so, the code ends up very messed up. I've even desperately tried adding double carets, but it didn't work either. Could anybody please help me find out what's WRONG?!

Re: Problem when creating batch file with batch file

Posted: 23 Jun 2014 09:31
by Compo
Try this:

Code: Select all

@echo off
title The Vault
color 0d

::initialization
if not exist "lckr0\passref.cmd" (
   if not exist "lckr0\" md "lckr0"
   goto :passref_creation)
pause
goto :eof

:passref_creation
(echo(@echo off
   echo(setlocal EnableDelayedExpansion
   echo(title Enter Password...
   echo(color 0b
   echo(mode con: cols=50 lines=5
   echo(set "chars= abcdefghijklmnopqrstuvwxyz1234567890"
   echo(set "password="
   echo(set "asterisk="
   echo(
   echo(:main
   echo(cls
   echo(echo(Password: %%password%%
   echo(choice /c %%chars: =%% /n /m "Password: %%asterisk%%"
   echo(set password=%%password%%!chars:~%%errorlevel%%,1!
   echo(set asterisk=%%asterisk%%*
   echo(goto :main)>"lckr0\passref.cmd"