Problem when creating batch file with batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
john924xps
Posts: 65
Joined: 08 Jun 2012 07:48

Problem when creating batch file with batch file

#1 Post by john924xps » 21 Jun 2014 09:48

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"

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Problem when creating batch file with batch file

#2 Post by npocmaka_ » 21 Jun 2014 10:10

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"


?

john924xps
Posts: 65
Joined: 08 Jun 2012 07:48

Re: Problem when creating batch file with batch file

#3 Post by john924xps » 23 Jun 2014 08:48

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?!

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Problem when creating batch file with batch file

#4 Post by Compo » 23 Jun 2014 09:31

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"

Post Reply