Batch process hides its own window, it's boring _dos/bat

Source: Internet
Author: User

Copy Code code as follows:

@echo off
:: Code by Lz-myst qq:8450919 Blog:http://hi.baidu.com/lzmyst http://www.clxp.net.cn
If "%1" NEQ "1" (
> "%temp%\tmp.vbs" echo Set WshShell = wscript.createobject^ (^ "wscript.shell^" ^)
>> "%temp%\tmp.vbs" Echo wshshell.run chr^ (34^) ^&%0 ^& chr^ (34^) ^& ^ "1^", 0
start/d "%temp%" Tmp.vbs
Exit

)
:: From here, is your batch code, DOS black box flashed over, go to the background run
Pause
:: You will see a CMD process in Task Manager that has a hidden window

How to hide the cmd window when running bat

The way to hide the cmd window while running a bat can edit a VBS script in which the batch program runs with a hidden window.
Copy Code code as follows:

Set ws = CreateObject ("Wscript.Shell")
Ws.run "cmd/c Batch program name", Vbhide

Copy the code above to Notepad, save it as "Runbat.vbs" or another name (the extension must be. vbs), and then click Run the generated script Runbat.vbs to hide the run of the specified batch program.
This VBS script can also be invoked directly in the bat environment to hide the bat itself.
Summary of their own, do a few examples, interested to go to the test Ah!
Copy Code code as follows:

Set ws = CreateObject ("Wscript.Shell")
Wscript.Sleep 1200 Ws.run "cmd/c start Winrar.exe", vbhide
Wscript.Sleep 2200 Ws.run "cmd/c start Msimn.exe", vbhide
Wscript.Sleep 1200 Ws.run "cmd/c start Iexplore.exe", vbhide


Here are a few experts to clean up

Several ways to hide the batch run window.
(1) Implemented by batch processing command. Disadvantage: You will see a window flashing away. Advantages: Simple, direct add can.

Copy Code code as follows:

@echo off
If "%1" = = "h" goto begin
Start Mshta vbscript:createobject ("Wscript.Shell"). Run ("" "%~nx0" "H", 0) (window.close) &&exit
: Begin
:: The following is a normal batch order, do not contain pause set/p and other interactive commands
Pause

(2) using the VBS script to achieve hidden. Disadvantage: Call trouble point. Advantages: Basic See no traces (not absolute, refers to the general user)

Hiderun.vbs

Copy Code code as follows:

CreateObject ("Wscript.Shell"). Run "cmd/c D:/test.bat", 0

Where D:/test.bat is your batch process path
......................................................................................................................... ............
Another idea is to convert the bat to a VBS, then the VBS generates a temporary BAT file, and then WScript.Shell.Run hides it to start the temporary bat.
Hiderun.bat

Copy Code code as follows:

Echo CreateObject ("Wscript.Shell"). Run "cmd/c d:/test.bat",0> $tmp. vbs
Cscript.exe/e:vbscript $tmp. vbs
Del $tmp. vbs

This batch does not actually hide the batch itself, but most of the following hides the rationale and basis of calling the batch process.
Hiderun.js

Copy Code code as follows:

New ActiveXObject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0);

What's the advantage of using JavaScript? JS string variables can be used in single quotes, so as to facilitate the command line as a parameter call, and JS very good support for multi-line statements; Separate it into one line. Note: JS to be case-sensitive, method
Parentheses must be used, and the end must have a semicolon. So it became the following command:

Copy Code code as follows:

Mshta "javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); Window.close () "

Typically, the system administrator pushes some scripts to the client and runs them, or copies the batch files to clients run by the user. But most scripts run with a black background DOS window, which allows many users to be unaware of the
Measures, or even misoperation to close the running window. Fortunately, the DOS window of a batch file can be hidden, and here are a few ways to hide the batch run window.
1. The basic
Hiderun.vbs
CreateObject ("Wscript.Shell"). Run "cmd/c D:/test.bat", 0
Where D:/test.bat is your batch process path
Another idea is to convert the bat to a VBS, then the VBS generates a temporary BAT file, and then WScript.Shell.Run hides it to start the temporary bat.
Hiderun.bat

Copy Code code as follows:

Echo CreateObject ("Wscript.Shell"). Run "cmd/c d:/test.bat",0> $tmp. vbs
Cscript.exe/e:vbscript $tmp. vbs
Del $tmp. vbs

This batch does not actually hide its batch itself, but most of the following hides the rationale and basis of calling the batch.
Hiderun.js
New ActiveXObject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); What's the advantage of
using JavaScript? JS string variables can be used in single quotes, so as to facilitate the command line as a parameter call, and JS very good support for multi-line statements; Separate it into one line. Note that JS is case-sensitive, the method
must be in parentheses, and the end must have a semicolon. So it becomes the following command:
Mshta "javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c d:/test.bat ', 0); Window.close () "
2. Using Shortcuts
If you want to hide a batch itself, you can refer to a shortcut in the attachment and modify the relevant path in the attachment to hide the start of your batch process. You can use a VBS to create a. lnk, which is actually done with a batch (echo a
vbs)
3. Using System services
You can set up a system service and then start the service to start the batch process. The disadvantage is that the startup service is slow and requires Administrator privileges
Runassrv add/cmdline: "c:/windows/system32/cmd.exe/c d:/test.bat"/name: "Mysrv"
net start Mysrv
4. At Scheduled tasks
use at to establish a scheduled task that can run in the background without entering the/interactive parameter. However, the build using at must have Administrator privileges
at 09:10 "cmd/c d:/test.bat"
and then the system will automatically run this bat with system privileges at 9:10

5. Use the Ftype file association
ftype Batfile=c:/windows/system32/mshta javascript:new activexobject (' Wscript.Shell '). Run (' cmd/c%1 ', 0); Window.close (); "
6. Other users
Windows 2K/XP supports multiple users, and if you can log on to another account's desktop in the background and then run a batch, you can completely achieve the hidden purpose of
7. Compile into executable
Many methods can be implemented, and the tools that can be used directly are Quick Batch file compiler.

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.