Batch several ways to minimize the running:
Minimize run the batch method: general
mode with cols = 20 lines = 1
if exist "Temp.bat" goto Start
>Temp.bat echo start /min "" "%~nx0"^&exit
start /min Temp.bat&exit
:Start
del "Temp.bat">nul
pause
exit
Comment:
The above assumptions are stored in the "min.bat" file
(1) mode con cols = 14 lines = 1 (this line can not)
Cmd buffer setting screen width is 14 characters, the number of lines is one line
(2)>Temp.bat echo start /min "" "%~nx0"^&exit
In the current directory Temp.bat file, the file contents are "start / min" "" min.bat "& exit". "^" Is an escape character, to ensure the normal symbol "&" is written to a text file. "% ~ Nx0" at runtime by replacing the batch file where the file name (is replaced by "min.bat" in this example).
(3) start / min Temp.bat & exit (starting from here, the following commands are executed in the CMD minimized)
Run on the new minimize the CMD window "Temp.bat" and exit the beginning of the run min.bat CMD window.
(4) Temp.bat minimize call min.bat
At this point Temp.bat exists, go to: Content after the row "Start".
Minimize run a batch Method Two: Good
Only one line of code, make a batch minimize run their own
if not "%~1"=="p" start /min cmd.exe /c %0 p&exit
Plus at the beginning of any batch, but this code is very dangerous, I forgot to add p 0% after the results. . . !
Explain the meaning of this code:
1.if not "% ~ 1" == "p" - the first argument if this batch of "% 1" is not "p", then ...
2.start / min cmd.exe / c-- minimize close after executing cmd.exe (cmd.exe Why 0% indirectly perform? The purpose is not to perform the exit end of the batch can automatically exit)
3.% 0 p-- batch itself with the parameter "p" (arbitrary parameter can)
4. & exit-- do not have to explain it!
Role is: to minimize the run itself (once!), This batch quit, and will not run indefinitely!
Minimize run batch Method three good :()
@echo off && mode con cols = 20 lines = 1 (the phrase is best not to)
%1 %2
start /min /i "" "%~nx0" goto min&&goto :eof
me:
Rem write code below
Batch several methods to hide the window run:
If you want to hide, then execute the batch, batch programs can not contain set / p, pause and other interactive commands, otherwise unable to perform a full batch!
Hide window to run a batch method: the best support system memory
@echo off
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, what you batch code, DOS black box fleeting, to the background of the
pause
:: You will see that there is a hidden CMD process in the Task Manager window
Hide window to run the batch method II: General
Hide cmd window while running the bat ways to edit a vbs script in which to hide the window to run a batch program.
Set ws = CreateObject("Wscript.Shell")
ws.run "cmd / c batch program name", vbhide
The above copy the code into Notepad, save it as "runbat.vbs" or any other name (extension must be .vbs), then click generate script runbat.vbs run, you can hide a specified batch program run.
This vbs script can be called directly in the environment bat, bat to hide their own purposes.
Hide window to run the batch method three: general
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
Hide window to run the batch method four:
Cons:'ll see a window fleeting. Advantages: simple, can be added directly.
@echo off
if "%1"=="h" goto begin
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
:: The following is the normal batch command, not containing pause set / p and other interactive command
pause
Hide window to run the batch method five:
Cons: call trouble spots. Advantages: basically do not see signs of (non-absolute, refers to the general user)
HideRun.vbs
CreateObject("WScript.Shell").Run "cmd /c D:/test.bat",0
Where D: /test.bat your batch path
Another idea is to convert bat to vbs, vbs then generates a temporary bat file, and then hide WScript.Shell.Run start this temporary bat.
HideRun.bat
echo CreateObject("WScript.Shell").Run "cmd /c D:/test.bat",0>$tmp.vbs
cscript.exe /e:vbscript $tmp.vbs
del $tmp.vbs
This batch batch itself does not actually make it hidden, but hidden beneath most of the principles and basis of the calling batch.
HideRun.js
new ActiveXObject('WScript.Shell').Run('cmd /c D:/Test.bat',0);
Javascript with what good is it? js string variable in single quotes, so as to facilitate the command-line arguments, and js well supported with multi-line statement; are separated into a single line. Note that: js case sensitive method
Must use parentheses, at the end there must be a semicolon. So it becomes the following command:
mshta "javascript:new ActiveXObject('WScript.Shell').Run('cmd /c D:/test.bat',0);window.close()"
Usually the system administrator to push the client and run some scripts, batch files or copy to the client by the user to run their own. But most of the script at runtime will pop up on a black background DOS window, it makes a lot of users at a loss, misuse or even close the window running. Fortunately, the batch file a DOS window can be hidden.
Hide window to run the batch six:
A shortcut, if you want to hide a batch itself, you can create a shortcut to a bat and then modify the shortcut path to hide the related start your batch. Vbs can be used to create a .lnk, in fact, in batch, too (a first echo
vbs out)
Hide window to run the batch seven:
Use system services, you can create a system service and then start the service to start the batch. The disadvantage is slow to start the service, you need administrator rights
runassrv add /cmdline:"C:/Windows/System32/cmd.exe /c D:/test.bat" /name:"mysrv"
net start mysrv
Hide window to run the batch eight:
Use at a scheduled task, you can build a program at a task that runs without input / interactive parameter can be the background. But use at construction must have administrator privileges
at 09:10 "cmd /c D:/Test.bat"
Then it will automatically run in the background the bat as SYSTEM at 9:10 System
Hide window to run the batch method nine:
Use file association ftype
ftype batfile=C:/Windows/System32/mshta "javascript:new ActiveXObject('WScript.Shell').Run('cmd /c%1',0);window.close();"
Hide run a batch method window ten:
Compiled into an executable file, many ways to achieve, you can directly use the tools bat2exe, Baidu search a lot.
Custom Batch window:
Window size is defined:
Syntax:
MODE con: COLS = [Window Width] LINES = [window height]
Window width values: ≥20, Height Value: 1≤h≤300
Example:
MODE with: COLS = 35 LINES = 17
Batch window foreground and background colors random transformation:
Code:
@echo off&setlocal enabledelayedexpansion
set "b=0123456789abcdef"&set "f=0123456789abcdef"&set /a r=%random%%%16&set /a s=%random%%%16
color !f:~%s%,1!!b:~%r%,1!
The following write code ::
Tutorial is completed, talked about here, surely we are already very familiar with the batch processing, batch processing more powerful you can dig out, ready to go, enjoy swimming in the ocean of a batch of it!