0

I hope you are having a great day!

So I came across a particular piece of code that didn't seem to work out for me and I was looking for the solution.

Here is the code:

cd "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\StartMenu\Programs\Startup\">> FriendlyVirus.bat

rem Saved in "C:\Users\%username%\desktop\Instant_Installl.bat">> FriendlyVirus.bat

    @echo @echo off>> VirusTerminator.bat
    @echo color a>> VirusTerminator.bat
    @echo title Virus Terminator>> VirusTerminator.bat
    @echo cls>> VirusTerminator.bat
    @echo echo.>> VirusTerminator.bat
    @echo set /P c=.>> VirusTerminator.bat
    @echo If "%c%"=="3814" goto :terminatey>> VirusTerminator.bat
    @echo echo.>> VirusTerminator.bat
    @echo goto :terminaten>> VirusTerminator.bat
    @echo :terminatey>> VirusTerminator.bat
    @echo del FriendlyVirus.bat>> VirusTerminator.bat
    @echo cls>> VirusTerminator.bat
    @echo echo.>> VirusTerminator.bat
    @echo echo Done! (Right)>> VirusTerminator.bat
    @echo pause>> VirusTerminator.bat
    @echo exit>> VirusTerminator.bat
    @echo :terminaten>> VirusTerminator.bat
    @echo cls>> VirusTerminator.bat
    @echo echo.>> VirusTerminator.bat
    @echo echo Done! (Wrong)>> VirusTerminator.bat
    @echo pause>> VirusTerminator.bat
    @echo exit>> VirusTerminator.bat
    echo.
    echo Finished.
    exit

All of the code works fine, except for one bit.

The line where it says: @echo If "%c%"=="3814" goto :terminatey>> VirusTerminator.bat is the problem.

what the code does is by running the main batch file, it creates multiple other batch files and enters code into them.

However, when I run the newly created batch file, it doesn't work as desired, and when I look at the code, it changed:

@echo If "%c%"=="3814" goto :terminatey>> VirusTerminator.bat

to

@echo If ""=="3814" goto :terminatey>> VirusTerminator.bat

removing the whole %c% part.

I tried putting it in quotation marks and also messing around with the percent signs.

I know the code is fully functioning apart from this because I can add the code in manually and it works as desired.

All answers are appreciated!!!

Thankyou!

Tezak
  • 36
  • 3
  • 3
    You need to double the percent symbols. `@echo If "%%c%%"=="3814" goto :terminatey>> VirusTerminator.bat` – Squashman Oct 05 '16 at 14:00
  • 2
    And instead of `C:\Users\%username%\AppData\Roaming\Microsoft` use `%APPDATA%\Microsoft`. And instead of `C:\Users\%username%\desktop` use `%USERPROFILE%\Desktop`. Open a command prompt window and run the command `set` to get displayed which environment variables are predefined by Windows for the user account. – Mofi Oct 05 '16 at 14:56
  • 1
    Possible duplicate of [Ignore percent sign in batch file](http://stackoverflow.com/questions/1907057/ignore-percent-sign-in-batch-file) – aschipfl Oct 05 '16 at 15:55

0 Answers0