Hide Command Window of .BAT file that Executes Another .EXE File

前端 未结 15 1947
猫巷女王i
猫巷女王i 2020-12-02 12:50

This is a batch file in Windows.

Here is my .bat file

@echo off
copy \"C:\\Remoting.config-Training\" \"C:\\Remoting.config\"

\"C:\\ThirdPar         


        
相关标签:
15条回答
  • 2020-12-02 13:26

    Try this:

    @echo off 
    copy "C:\Remoting.config-Training" "C:\Remoting.config"
    start C:\ThirdParty.exe
    exit
    
    0 讨论(0)
  • 2020-12-02 13:26

    run it under a different user. assuming this is a windows box, create a user account for scheduled tasks. run it as that user. The command prompt will only show for the user currently logged in.

    0 讨论(0)
  • 2020-12-02 13:26

    Using Windows API we can start new process, a console application, and hide its "black" window. This can be done at process creation and avoid showing "black" window at all.

    In CreateProcess function the dwCreationFlags parameter can have CREATE_NO_WINDOW flag:

    The process is a console application that is being run
    without a console window. Therefore, the console handle
    for the application is not set. This flag is ignored if
    the application is not a console application
    

    Here is a link to hide-win32-console-window executable using this method and source code.

    hide-win32-console-window is similar to Jamesdlin's silentbatch program.

    There is open question: what to do with program's output when its window does not exist? What if exceptions happen? Not a good solution to throw away the output. hide-win32-console-window uses anonymous pipes to redirect program's output to file created in current directory.

    Usage

    batchscript_starter.exe full/path/to/application [arguments to pass on]

    Example running python script

    batchscript_starter.exe c:\Python27\python.exe -c "import time; print('prog start'); time.sleep(3.0); print('prog end');"
    

    The output file is created in working directory named python.2019-05-13-13-32-39.log with output from the python command:

    prog start
    prog end
    

    Example running command

    batchscript_starter.exe C:\WINDOWS\system32\cmd.exe /C dir .
    

    The output file is created in working directory named cmd.2019-05-13-13-37-28.log with output from CMD:

     Volume in drive Z is Storage
     Volume Serial Number is XXXX-YYYY
    
     Directory of hide_console_project\hide-win32-console-window
    
    2019-05-13  13:37    <DIR>          .
    2019-05-13  13:37    <DIR>          ..
    2019-05-13  04:41            17,274 batchscript_starter.cpp
    2018-04-10  01:08            46,227 batchscript_starter.ico
    2019-05-12  11:27             7,042 batchscript_starter.rc
    2019-05-12  11:27             1,451 batchscript_starter.sln
    2019-05-12  21:51             8,943 batchscript_starter.vcxproj
    2019-05-12  21:51             1,664 batchscript_starter.vcxproj.filters
    2019-05-13  03:38             1,736 batchscript_starter.vcxproj.user
    2019-05-13  13:37                 0 cmd.2019-05-13-13-37-28.log
    2019-05-13  04:34             1,518 LICENSE
    2019-05-13  13:32                22 python.2019-05-13-13-32-39.log
    2019-05-13  04:55                82 README.md
    2019-05-13  04:44             1,562 Resource.h
    2018-04-10  01:08            46,227 small.ico
    2019-05-13  04:44               630 targetver.h
    2019-05-13  04:57    <DIR>          x64
                  14 File(s)        134,378 bytes
                   3 Dir(s)  ???,???,692,992 bytes free
    

    Example shortcut for running .bat script

    Target field:

    C:\batchscript_starter.exe C:\WINDOWS\system32\cmd.exe /C C:\start_wiki.bat
    

    Directory specified in Start in field will hold output files.

    0 讨论(0)
  • 2020-12-02 13:27

    Please use this one, the above does not work. I have tested in Window server 2003.

    @echo off 
    copy "C:\Remoting.config-Training" "C:\Remoting.config"
    Start /I "" "C:\ThirdParty.exe"
    exit
    
    0 讨论(0)
  • 2020-12-02 13:36

    Compile the batch file to an executable using Batch2Exe http://www.f2ko.de/programs.php?lang=en&pid=b2e. Use the "Invisible Window" option.

    0 讨论(0)
  • 2020-12-02 13:40

    Or you can use:

    Start /d "the directory of the executable" /b "the name of the executable" "parameters of the executable" %1
    

    If %1 is a file then it is passed to your executable. For example in notepad.exe foo.txt %1 is "foo.txt".

    The /b parameter of the start command does this:

    Starts an application without opening a new Command Prompt window. CTRL+C handling is ignored unless the application enables CTRL+C processing. Use CTRL+BREAK to interrupt the application.

    Which is exactly what we want.

    0 讨论(0)
提交回复
热议问题