【问题标题】:How to run multiple commands in one batch file?如何在一个批处理文件中运行多个命令?
【发布时间】:2015-09-23 07:31:36
【问题描述】:

我想在一个批处理文件中运行多个命令。

我尝试了 &、&&、start、/wait、call、:begin 和 goto begin 命令,但没有成功。

这是我的命令:

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

sc config remoteregistry start= auto 

sc start remoteregistry 

sc config Schedule start=auto 

sc start Schedule 

sc stop McAfeeFramework

sc configure McAfeeFramework startup= disabled

sc stop  McShield

sc configure  McShield startup= disabled

sc stop McTaskManager 

sc configure McTaskManager startup= disabled

netsh advfirewall set AllProfiles state off 

sc stop MpsSvc

sc config MpsSvc start= disabled

【问题讨论】:

  • 不知道你的意思 - 这些不是多个命令吗?你是说同时吗?
  • 是的 cmd 不想在双击或以管理员身份运行时全部运行它们,但它只运行第一个。
  • 只运行第一行?见cmd /?。特别关注/k/c
  • 谢谢我管理我只是把 start 放在每个并行命令的开头:)
  • 我建议@Stephan 将其评论转换为答案并由 OP 选择它,这样我们其他人就知道这个问题已经解决了......

标签: windows batch-file cmd


【解决方案1】:
C:\Windows\System32\cmd.exe /k <command>

启动一个新的 cmd 上下文执行,但/k 保持该新上下文打开。您想在执行后关闭它,以便可以执行来自原始上下文的进一步命令。使用/c 而不是/k 这样做。

cmd /?中描述

【讨论】:

  • 谢谢,但我做到了,但知道其他事情仍然很好。
【解决方案2】:

好吧,批处理脚本已经默认执行了,但我猜您在 cmd.exe 上使用 /K 是不必要且有害的,尽管 A / C 可以完成这项工作,但请记住,这不是必需的.

File1.bat*

C:\Windows\System32\cmd.exe /c %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f

sc config remoteregistry start= auto 

sc start remoteregistry 

sc config Schedule start=auto 

sc start Schedule 

sc stop McAfeeFramework

sc configure McAfeeFramework startup= disabled

sc stop  McShield

sc configure  McShield startup= disabled

sc stop McTaskManager 

sc configure McTaskManager startup= disabled

netsh advfirewall set AllProfiles state off 

sc stop MpsSvc

sc config MpsSvc start= disabled

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 2015-11-15
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    相关资源
    最近更新 更多