如何在批处理文件中设置 RANDOM?

How to set RANDOM in a batch file?

所以我写了这个批处理文件。

我需要使用某种随机函数在 9 个 .exe 文件之间进行选择。

其中一个 .exe 文件是 "OPTION1.exe",所以我想从 "OPTION2.exe, OPTION3.exe..." 等批处理到 select,它们都位于与第一个相同的文件夹中一.

我想知道是否可行以及如何实现。

谢谢你的时间。

@echo off
:loop
TASKKILL /F /IM "Software.exe"
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software
TIMEOUT /T 15
start OPTION1.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe 
TIMEOUT /T 400
TASKKILL /F /IM "Chrome.exe"
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO loop
set /a executable=(%random% %% 9) + 1
set "executablename=OPTION%executable%.exe"
echo %executablename%

应该会显示一个随机的可执行文件名称 OPTION1.exe .. OPTION9.exe

好吧,您可以对提供的代码进行一些改进。这是修改后的代码:

echo off
cls
:loop
TASKKILL /F /IM Software.exe
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 5
cd C:\Users\admin\Documents\Software
start Software.exe
TIMEOUT /T 15
start OPTION1.exe
start OPTION2.exe
start OPTION3.exe
TIMEOUT /T 10
start connect.exe
TIMEOUT /T 15
cd C:\Program Files (x86)\Google\Chrome\Application
start Chrome.exe 
TIMEOUT /T 400
TASKKILL /F /IM Chrome.exe
TIMEOUT /T 10
cd C:\Users\admin\Documents\Software
start disconnect.exe
TIMEOUT /T 15
cls
GOTO :loop