Running a CMD or BAT in silent mode

前端 未结 11 1018
夕颜
夕颜 2020-11-28 03:51

How can I run a CMD or .bat file in silent mode? I\'m looking to prevent the CMD interface from being shown to the user.

相关标签:
11条回答
  • 2020-11-28 04:17

    Use Advanced BAT to EXE Converter from http://www.battoexeconverter.com

    This will allow you to embed any additional binaries with your batch file in to one stand alone completely silent EXE and its freeware

    0 讨论(0)
  • 2020-11-28 04:17

    I'm created RunApp to do such a job and also using it in my production env, hope it's helps.

    The config like below:

    file: config.arg

    :style:hidden
    
    MyBatchFile.bat
    arg1
    arg2
    

    And launch runapp.exe instead.

    0 讨论(0)
  • 2020-11-28 04:18

    I have proposed in StackOverflow question a way to run a batch file in the background (no DOS windows displayed)

    That should answer your question.

    Here it is:


    From your first script, call your second script with the following line:

    wscript.exe invis.vbs run.bat %*
    

    Actually, you are calling a vbs script with:

    • the [path]\name of your script
    • all the other arguments needed by your script (%*)

    Then, invis.vbs will call your script with the Windows Script Host Run() method, which takes:

    • intWindowStyle : 0 means "invisible windows"
    • bWaitOnReturn : false means your first script does not need to wait for your second script to finish

    See the question for the full invis.vbs script:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run """" & WScript.Arguments(0) & """" & sargs, 0, False
                                                             ^
                                 means "invisible window" ---| 
    

    Update after Tammen's feedback:

    If you are in a DOS session and you want to launch another script "in the background", a simple /b (as detailed in the same aforementioned question) can be enough:

    You can use start /b second.bat to launch a second batch file asynchronously from your first that shares your first one's window.

    0 讨论(0)
  • 2020-11-28 04:20

    Use Bat To Exe Converter to do this

    http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html
    (Choose Direct Download Link)

    1 - Open Bat to Exe Converter, select your Bat file.
    2 - In Option menu select "Invisible Application", then press compile button.

    Done!

    0 讨论(0)
  • 2020-11-28 04:26

    Another way of doing it, without 3rd party programs nor converters ("batch to exe" programs actually just put your batch file in the tmp folder and then run it silently so anyone can just fetch it from there an get your code) no vbs files (because nobody knows vbs) just one line at the beginning of the batch file.

    @echo off > NUL
    
    0 讨论(0)
提交回复
热议问题