【问题标题】:How to make a batch file run a program and then set priority higher?如何让批处理文件运行程序,然后设置更高的优先级?
【发布时间】:2015-12-06 10:51:32
【问题描述】:

您好,我已经看到了几个这样的问题,但是当我尝试按照这些说明进行操作时,我觉得我错过了一些东西

>

创建一个.bat文件来运行程序,使用超时命令等待几秒钟让辅助进程运行,然后使用下面的命令将辅助进程的优先级更改为你想要的。

wmic process where name="process name" CALL setpriority "value"

可能的值:“空闲”、“低”、“低于正常”、“正常”、“高于正常”、>“高优先级”、“实时”

我制作了一个包含这些行的批处理文件:

start "C:\Program Files (x86)\Origin Games\STAR WARS Battlefront\starwarsbattlefront.exe"  
timeout /t 60 /nobreak 
wmic process where name="starwarsbattlefront.exe" CALL setpriority "above normal"

当我运行它时,我得到一个错误。我已经阅读了一堆关于 StackoverFlow 和 SuperUser 的文章,但没有一篇文章明确了最终产品。很抱歉看起来很无知(因为我是)我觉得我错过了一些明显的东西。谁能帮我解决这个问题?

提前致谢:)

编辑 *

错误是:'C'不是内部或外部命令、可运行程序或批处理文件。

【问题讨论】:

  • 请编辑您的问题以包含错误消息的文本。
  • 或者,在您的 start 命令之后添加 ""。
  • @JosefZ,我认为删除 start 让批处理脚本等到 *.exe 文件退出,这不是 OP 的意图...
  • start "" "C:\Program Files (x86)\ … \starwarsbattlefront.exe"。 SomethingDark 和 aschipfl 是对的。

标签: batch-file command-line cmd cpu explorer


【解决方案1】:
::Launches Star Wars Battlefront and sets priority to "above normal"
@echo off

START /ABOVENORMAL /D "C:\Program Files (x86)\Origin Games\STAR WARS Battlefront\" "" "starwarsbattlefront.exe"
timeout /t 60 /nobreak
wmic process where name="starwarsbattlefront.exe" CALL setpriority "above normal"

echo Done.
TIMEOUT 10
exit

启动应用程序的更好命令。有了这个,你不会有任何问题:]。 “/D”基本上是“来自目录”。以 :: 开头的行只是一个注释。执行 .bat 文件时您不会看到它。结尾部分只显示文本“完成”。然后在关闭前从 5 倒计时到 0。

/ABOVENORMAL 可能无法按预期工作,因为启动 .exe 可能会提示 Origin 启动应用程序。因此,优先级可能不适用于《星球大战前线》。这就是我留下“wmic”部分的原因。但是它应该适用于其他应用程序。

可能有更好更快的方法来做到这一点。

【讨论】:

    【解决方案2】:

    这就是我在 .bat 文件上编写脚本的方式。

    @ECHO OFF
    CD "C:\Program Files (x86)\Origin Games\STAR WARS Battlefront
    START starwarsbattlefront.exe
    WMIC process where name="starwarsbattlefront.exe" CALL setpriority "high"
    EXIT
    

    【讨论】:

    • 请描述WHY你认为这比OP的问题更好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 2021-05-20
    • 2023-03-29
    相关资源
    最近更新 更多