Windows脚本 - 运行静默,但等待完成/返回正确的代码 [英] Windows script - run silent but wait for completion / return right code

查看:603
本文介绍了Windows脚本 - 运行静默,但等待完成/返回正确的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:




  • 我有一个BAT文件需要很长时间才能运行(1分钟至70分钟)

  • 我计划使用Windows调度程序每10分钟运行一次

  • 如果在运行时再次进行调度,这是很好的)



我的问题是我需要我的BAT默认运行,而不是。所以,我想使用Windows脚本启动它,如下所示:

 设置WshShell = CreateObject(WScript.Shell) 
WshShell.Run chr(34)& C:\Batch Files\syncfiles.bat& Chr(34),0
设置WshShell =没有

不幸的是,当我安排这个脚本,它做的工作,但立即返回 ,使Windows调度程序认为任务完成,实际上,BAT只是自己在某个地方运行。



<因此,Windows将在10分钟后重新安排工作,并进行多次运行。



我需要:



有没有办法告诉Windows脚本文件等待.Run命令的目标在进行/退出之前完成?基本上,我想要它像我发起另一个线程,然后调用加入,所以它做同样的事情,BAT将具有,但没有显示控制台窗口。



其他解决方案



告诉我任何其他方式让这个BAT无声地执行(PowerShell命令,无论如何),我会接受作为一个解决方案。只是不要告诉我,在C ++ / C#应用程序周围写一个完整的,这是超额的:)






运行: Windows Server 2008 R2

解决方案

这里疯狂...



创建一个文件 invisible.vbs

  CreateObject(Wscript.Shell)。运行& WScript.Arguments(0)& ,0,True 

然后在任务调度程序中,调用您的脚本,如下所示: / p>

  wscript.exeC:\Batch Files\invisible.vbsC:\Batch Files\syncfiles蝙蝠

我测试了它,这确实有效:没有命令窗口,任务被认为是运行直到批处理脚本结束。



信用转至 https://超级用户。 com / a / 62646/40362






对于2008 R2,使invisible.vbs具有此内容,直接执行它。它将默认运行BAT并等待完成。

 设置objShell = WScript.CreateObject(WScript.Shell)
objShell.RunD:\IUpdateScript.bat,0,true


Here's my situation:

  • I have a BAT file that takes a long time to run (1minute to 70 minutes)
  • I schedule it with Windows scheduler to run every 10 minutes
  • If it schedules again while it is still running, nothing happens (this is good)

My problem is that I need my BAT to run silently, and it doesn't. So, I want to launch it with a Windows script like the following:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing

Unfortunately, when I schedule this script, it does the job but returns instantly, making Windows scheduler think the task is finished when in reality the BAT is just running off by itself somewhere.

Because of this, Windows will reschedule the job again 10 minutes later and make multiple run.

What I need:

Is there a way to tell the Windows script file to wait for the target of the .Run command to complete before progressing/exiting? Basically, I want it to act like I launched another thread and then called join on it, so it does the same thing the BAT would have, but without displaying the console window.

Other Solutions

Tell me any other way to get this BAT to execute silently (powershell commands, whatever) and I'll accept it as a solution as well. Just don't tell me to write a full on C++/C# appliation around it, that's overkill :)


Running: Windows Server 2008 R2

解决方案

Here goes the madness...

Create a file invisible.vbs:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, True

Then in the task scheduler, call your script like this:

wscript.exe "C:\Batch Files\invisible.vbs" "C:\Batch Files\syncfiles.bat"

I tested it and this does really work: No command window, and the task is considered running until the batch script ends.

Credit goes to https://superuser.com/a/62646/40362.


For 2008 R2 make invisible.vbs have this content, and just execute it directly. It will run the BAT silently and wait for completion.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "D:\IUpdateScript.bat", 0, true

这篇关于Windows脚本 - 运行静默,但等待完成/返回正确的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆