一个进程被批处理文件启动的另一个进程启动后如何运行命令?

问题描述 投票:0回答:1

有谁知道如何创建一个批处理来启动一个应用程序,然后将另一个应用程序的进程优先级设置为低于正常的优先级,接下来等待另一个进程启动,最后将最后启动的进程的进程优先级设置为更高优先级高于正常?

如果您能帮助我,我将不胜感激,因为这是我的生意(网吧)。

所以我需要批处理文件来启动Valorant(技术上是Valorant配置上的Riot客户端)。然后在用户登录后将 Chrome 进程设置为低进程优先级,并将 Valorant (技术上是

VALORANT-Win64-Shipping.exe
)设置为高进程优先级。

以下是该任务所需的命令。

在cmd上运行Valorant(Riot登录客户端)的命令。

"C:\Riot Games\Riot Client\RiotClientServices.exe" --launch-product=valorant --launch-patchline=live

Chrome 设置为低优先级的命令(并阻止 Chrome 占用我电脑的全部 CPU 资源。)

wmic process where name="chrome.exe" call setpriority "64"

Valorant(游戏进程)设置为高优先级的命令。

wmic process where name="VALORANT-Win64-Shipping" call setpriority "128"

还请注意:登录客户端启动后,游戏进程并不会立即开始。执行第一个命令后必须添加等待游戏进程开始的代码,这基本上是我的问题。

batch-file
1个回答
0
投票

此任务的注释批处理文件可能是:

@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem Start Riot client as parallel running separate process.
start "" /D"C:\Riot Games\Riot Client" "C:\Riot Games\Riot Client\RiotClientServices.exe" --launch-product=valorant --launch-patchline=live

rem Define 120 seconds as maximum time for waiting for game process.
set RetryCount=120

rem In a loop wait one second, then look up in task list if the game process
rem is already running. If game process is running, exit the loop and change
rem the process priorities. Otherwise decrement the retry counter and exit
rem the loop on reaching value zero with informing the batch file user that
rem game process was not started within two minutes.

:WaitLoop
%SystemRoot%\System32\timeout.exe /T 1 /NOBREAK >nul
%SystemRoot%\System32\tasklist.exe /FI "IMAGENAME eq VALORANT-Win64-Shipping.exe" /NH 2>nul | %SystemRoot%\System32\find.exe /C /I "VALORANT-Win64-Shipping" >nul
if not errorlevel 1 goto GameStarted
set /A RetryCount-=1
if not %RetryCount% == 0 goto WaitLoop

echo Valorant game was not started within two minutes.
echo(
pause
goto EndBatch

:GameStarted
%SystemRoot%\System32\wbem\wmic.exe PROCESS where name="chrome.exe" CALL SetPriority 64 >nul
%SystemRoot%\System32\wbem\wmic.exe PROCESS where name="VALORANT-Win64-Shipping.exe" CALL SetPriority 128 >nul

:EndBatch
endlocal

要了解所使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完整、仔细地阅读每个命令显示的帮助页面。

  • echo /?
  • endlocal /?
  • find /?
  • goto /?
  • if /?
  • pause /?
  • rem /?
  • set /?
  • setlocal /?
  • start /?
  • tasklist /?
  • timeout /?
  • wmic /?
  • wmic process /?
  • wmic process call /?
  • wmic process call setpriority /?

另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.