简体   繁体   English

通过任务计划程序运行.bat脚本时,如何防止显示cmd.exe窗口?

[英]How can I prevent a cmd.exe window from showing when a .bat script is run via Task Scheduler?

I have a .bat script scheduled to run every 5 minutes via Windows Task Scheduler on a Windows Server 2008. 我有一个.bat脚本计划通过Windows Server 2008上的Windows Task Scheduler每5分钟运行一次。

.bat script: .bat脚本:

C:\Windows\SysWOW64\cscript.exe C:\scriptord.vbs //Nologo A > \\192.168.100.1\accounts\scriptord
C:\Windows\SysWOW64\cscript.exe C:\scriptord.vbs //Nologo B > \\192.168.100.2\accounts\scriptord
C:\Windows\SysWOW64\cscript.exe C:\scriptord.vbs //Nologo C > \\192.168.100.3\accounts\scriptord

Problem 问题

The problem is that every 5 minutes I get a black and white cmd.exe window on screen that stays for around 2 minutes while the script runs. 问题是每隔5分钟我会在屏幕上看到一个黑白的cmd.exe窗口,该窗口在脚本运行时会停留约2分钟。

How can I prevent this window from opening when Task Scheduler runs it? 如何在Task Scheduler运行时阻止此窗口打开?

最简单的解决方案通常是在不同的用户帐户下运行任务。

使用NT AUTHORITY\\SYSTEM作为用户,除非脚本仅需要用户有权访问的资源(例如远程共享)

You can call the batch script using VBS. 您可以使用VBS调用批处理脚本。 The below code will hide the console 下面的代码将隐藏控制台

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("Batchfile.bat"), 0, True

so run this script through windows task scheduler instead of the batch and the console will no longer appear. 因此,请通过Windows Task Scheduler(而不是批处理)运行此脚本,并且控制台将不再显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM