Niels
Niels

Reputation: 23

How to echo %random% instead of a random number in batch

How to echo %random instead of a random number. I'm makeing a benchmarking/virus batch that pushes any pc to the max. I want it to write a program in a loop and run it in al loop. that file it writes I want to run in a loop. The Problem is is that I cant echo a variable as %variable%...

Here is the program I am trying to make:

@echo off
:start
set rn=%random%
cd %userprofile%
goto createcopy
:runnew
start %rn%
goto start
:createcopy
echo "echo @echo off >>%rn%.bat".bat
echo "echo :start >>%rn%.bat"%rn%.bat
echo "echo set rn= >>%rn%.bat"%rn%.bat
echo "echo cd %userprofile% >>%rn%.bat"%rn%.bat
echo "echo start %rn%>>%rn%.bat">>%rn%.bat
pause
goto runnew

Please help, and if you do thank you in advance!

Upvotes: 1

Views: 920

Answers (1)

aschipfl
aschipfl

Reputation: 34909

To print the literal string %Random% by a batch file, you need to escape the % signs by doubling them, so the following accomplishes that:

rem This prints `%Random%` to the console:
echo %%Random%%

To do the same in command prompt directly, use the following command line:

rem This prints `%Random%` to the console:
echo ^%Random^%

To output special characters like <, >, |, &, (, ) and ^, which are not enclosed within a pair of "", escape them by preceding a ^ sign like in the following example:

rem This prints `<Tag>` to the console:
echo ^<Tag^>

This works for both batch files and command prompt.

Upvotes: 2

Related Questions