隐形模式下运行的主bat文件 [英] Running master bat file in invisible mode

查看:105
本文介绍了隐形模式下运行的主bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 master.bat 文件里面有...

I have a master.bat file which has...

call file1.bat
call file2.bat
call file3.bat
call file4.bat

我想安排它在我的Windows Server 2008上以静默/无形mode.I'm运行寻找一些方式来运行这个 master.bat 无任何可见的用户(无窗,CMD界面,任务栏上没有名字等。)
我不想任何批量安装到exe文件的软件。

I want to schedule it on my Windows server 2008 to run in silent/invisible mode.I'm looking for some way to run this master.bat without anything visible to the user (no window, CMD interface ,no taskbar name etc..) I don't want to install any batch to exe software.

我试图通过改变用户正在运行的任务系统,它已经完成的工作,但我不能在实际做到这一点。
我发现,Windows脚本宿主的run方法可以让你在不可见的模式.....

I tried by changing the User running the task to "SYSTEM" and it has the work done but I can't do this in actual. I have found that Windows Script Host’s Run Method allows you to run a script in invisible mode as.....

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

但没有更多的文件,请:)任何其他建议这一点。

but no more file please :) any other suggestion for this.

EDIT1

考虑到有限的选择available..it会即可使用Windows脚本宿主的运行方法,但如何我可以安排的任务计划程序master.vbs ..?

Considering the limited options available..it would be OK to use Windows Script Host’s Run Method,but how i can schedule master.vbs in task scheduler.. ?

推荐答案

有关它的一个扩展视图,检查混合批次/ VBScript中/ javascript文件在这里计算器。

For an extended view of it, check for hybrid batch / vbscript / javascript files here in stackoverflow.

保存为master.cmd并根据需要进行调整。

Save this as master.cmd and adapt as needed.

@if (@This==@IsBatch) @then
@echo off
rem **** batch zone *********************************************************

    rem Check if started from javascript part of script.
    rem We are checking an environment variable set from javascript part.
    if "%_run_hidden_%"=="true" (
        goto startBatchWork
    )

    rem if not started from javascript, call javascript part to restart batch.
    wscript //E:JScript "%~dpnx0" 
    exit /b

:startBatchWork

    rem Here starts the real work of the batch file

    msg %username% "Batch file running hidden"





    rem End of batch area. Ensure batch ends execution before reaching
    rem javascript zone
    exit /b

@end
// **** Javascript zone *****************************************************
// Instantiate the needed component to interact with Shell
var shell = WScript.CreateObject('WScript.Shell');

    // Set the environment variable that the batch part will check to know
    // it's running hidden
    shell.Environment('Process').Item('_run_hidden_')='true';

    // start the batch part of the script calling %comspec% with the current
    // script as parameter, hidden (0) and not waiting for it to end (false)
    shell.Run('"' + shell.ExpandEnvironmentStrings('%comspec%') + '" /c "' + WScript.ScriptFullName + '"', 0, false );

    // All done. Exit
    WScript.Quit(0);

这篇关于隐形模式下运行的主bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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