Windows Batch Processing

Source: Internet
Author: User

1. Introduction

On Windows, it's often necessary to do some repetitive work. For example, in different workplaces need to switch different IP, for example, sometimes need to 1~n a bunch of files to rename, and then we need to delete a lot of files, the names of these files are similar, but not in the same directory to stay ... The first time can endure, manually completed, but the number of times, will feel special trouble and boring, so began to write a program in a programming language to deal with, such as java,c++, but after the completion of the time to find more than the manual processing more .... At this time, some simple batch processing commands will bring infinite convenience.

The purpose of this blog is to not take the time to systematically memory these batch commands, so every time you encounter the need to use batch processing, Baidu-related statements, update records here.

Current update on: October 6, 2015 14:25:18;

2. Syntax

① environment: Under Windows, write a batch program is very simple, in any directory, right-create a new text document, open write code after saving (note coding, otherwise may be garbled), then the file. txt suffix to. bat suffix, double-click to run.

②echo: Print. Such as:

echo Hello world!

③@:@ indicates that the command is not displayed before a command is added. Such as:

@echo Hello world!

④echo off: After the command is executed, all commands are not displayed (equivalent to adding @ at the end of all commands, which is not valid for itself).

⑤pause: Paused. Press any key to continue.

⑥title: Sets the window caption. Such as:

Title Hello World

:: Tags. Use with Goto. Such as:

: Lable1

::: Comment. Such as:

:: This is a note

⑧goto: Jumps to a label. Such as:

Goto : Lable1

⑨ Set IP: for example:

Set Address "Local Area Connection" Static 192.168.0.99 255.255.255.0 192.168.0.1 1

where "Local Area Connection" is the name of the adapter you want to set, followed by the IP, gateway, subnet mask.

⑩ set up DNS: for example:

set DNS "Local Area Connection" static 192.168.0.1 Primary

? set/p xxx=: For example:

@set /P var=@echo  %var%@Pause

This means: Accept the keyboard input and assign the input value to Var. Where%var% refers to the Var variable.

? If condition (command) Else command, such as:

@if 1==1 (echoelseecho  does not set @pause

3. Case studies

①hello World

@echo Hello world! @title Hello World
@ Pause

② One-click IP (gateway, subnet mask, DNS)

@echo offEcho============== One-click Fill ip=============Title One-click Fill IPSetip1=192.168.1.2Setip2=172.16.42.254Echo0: ExitEcho1:%ip1%Echo2:%ip2%Set/P ip=Please enter a number:if%ip%==0Goto : Exitif%ip%==1Goto : Ip1if%ip%==2Goto : Ip2: Ip1EchoSetting ip:%ip1% ...Netsh Interface IPSetAddress "Local Area Connection" Static%ip1% 255.255.255.0 192.168.1.1Netsh Interface IPSetDNS "Local Area Connection" static 222.246.129.81PrimaryEchoSet SuccessGoto : Exit: Ip2EchoSetting ip:%ip2% ...Netsh Interface IPSetAddress "Local Area Connection" Static%ip2% 255.255.255.0 172.16.42.1Netsh Interface IPSetDNS "Local Area Connection" static 222.246.129.81PrimaryEchoSet SuccessGoto : Exit: ExitEchoByePauseExit

Windows Batch Processing

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.