Let the bat file run in the background

Source: Internet
Author: User

Reprint: http://blog.csdn.net/carl6148/article/details/7905549
BAT file runtime will have a black cmd.exe window, very scary, even if the start/min command to run the bat file, the computer will still have the relevant icon under the taskbar, how to let the bat file in the background silently invisible to run it? Here are some ways to achieve your goal.

Method One
BAT has a hidden window command, very simple, just need to add a piece of code at the head of the code on it.
@echo off
If "%1" = = "h" goto begin
Mshta vbscript:createobject ("Wscript.Shell"). Run ("%~nx0 h", 0) (window.close) &&exit
: Begin
:: Here is your own code.

Method Two
Create a new Notepad in the same directory as your batch and enter:
DIM Objshell Set Objshell=wscript.createobject ("Wscript.Shell")
Ireturn=objshell.run ("cmd.exe/c C:\1.bat", 0, TRUE)
(where Win.bat for your own batch name, change yourself)
Then save this notepad as a file with the suffix. VBE, and then you can just run the VBE file to achieve your goal!
A simple point to write:
Set ws = CreateObject ("Wscript.Shell")
Ws.run "cmd/c C:\1.bat", 0
Or
CreateObject ("Wscript.Shell"). Run "cmd/c C:\1.bat", 0
(This kind of writing a lot of kill the poison, need to replace the parameter 0)
The last 0 refers to the window parameters, using:
0 hide the window and activate another window.
1 Activates and displays a window. If the window is minimized or maximized, it reverts to its original size and position.
2 Activates the window and displays it in a minimized format.
3 Activates the window and displays the window to maximize it.
4 Displays the nearest size and position of the window. The active window remains active.
5 Activates and displays the window at the current size and position.
6 minimizes the specified window and activates the Next top-level window sorted by Z-order.
7 Minimize the display window. The active window remains active.
8 Displays the window in its current state. The active window remains active.
9 activates and displays the window. If the window is minimized or maximized, it reverts to its original size and position. This flag should be specified when the minimized window of the application is restored.

Let the bat file run in the background

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.