Production of batch processing applet

1. Introduction

Batch processing is a technology that automates a series of computer tasks in a predefined sequence. It is implemented through batch scripts or command files, which can run multiple commands or programs in batches without manual intervention.

Advantages of batch scripts

1. Automation: Batch processing can automatically perform repetitive tasks without manual intervention, reducing labor and time costs.

2. Batch processing: Batch processing can process multiple tasks at the same time and improve work efficiency.

3. Reduce errors: Batch processing can reduce errors caused by human factors and ensure the accuracy and consistency of tasks.

4. Resource optimization: Batch processing can reasonably arrange the use of computer resources and improve the overall performance of the system.

2. Application environment

1. Perform repetitive tasks: When the same or similar tasks need to be performed repeatedly, using batch processing can save time and energy.

2. Batch processing of files: If you need to perform the same operation or processing on multiple files, batch processing can be completed at one time.

3. Automated system management: Batch processing can be used for system management tasks, such as backup files, scheduled tasks, etc.

3. Examples

1. Windows basic function applet

1.Source code
@echo off
color 6e
ping 127.0.0.1 /n 2 >nul
color 5f

title 小程序
:menu
cls
echo.
echo ==========================
echo windows基本功能小程序
echo ==========================
echo 1.定时关机
echo 2.查看IP
echo 3.查看开启的端口
echo 4.查看所有进程
echo 5.关闭进程
echo 6.退出
echo 7.查看计算机详细信息
echo 8.查看磁盘总空间和剩余空间
echo 9.远程桌面
echo.
set /p num=请输入选项:
if "%num%"=="1" goto a
if "%num%"=="2" goto b
if "%num%"=="3" goto c
if "%num%"=="4" goto d
if "%num%"=="5" goto e
if "%num%"=="6" goto f
if "%num%"=="7" goto g
if "%num%"=="8" goto h
if "%num%"=="9" goto i
echo 请输入正确的值
pause
goto menu
:a
set /p time=请输入时间:
shutdown -s -t %time%
echo 定时关机已经设置完毕,谢谢使用!
pause
goto menu
:b
ipconfig
pause
goto menu
:c
netstat -ano
pause
goto menu
:d
tasklist
pause
echo 按任意键继续!
goto menu
:e
set /p gg=请输入进程号:
taskkill /f /pid %gg%
echo 谢谢使用!
pause
goto menu
:f
exit
:g
systeminfo
pause
goto menu
:h
fsutil volume diskfree c:
pause
goto menu
:i
mstsc
pause
goto menu
2. Run screenshot

 3.Explain 

Of course, the following is an explanation of each line of code:

@echo off

This code turns off the echo function of the command prompt window, that is, the command itself is not displayed on the window when executing the command.

color 6e

This code sets the background color of the Command Prompt window to dark yellow and the foreground color to bright yellow.

ping 127.0.0.1 /n 2 >nul

This code is used to delay execution and perform local loopback testing by sending two packets to itself. The purpose is to pause the program for a period of time.

color 5f

This line of code sets the background color of the Command Prompt window to dark purple and the foreground color to bright purple.

title applet

This code sets the title of the command prompt window to "Applet".

:menu

This code defines a label for jumps in the program. The label is called "menu".

cls

This code clears the contents of the command prompt window and achieves a clear screen effect.

echo.
echo ============
echo Welcome to the mini program
echo ============
echo 1. Schedule shutdown
echo 2. View IP
echo 3. View open ports
echo 4. View all processes
echo 5. Close the process
echo 6. Exit
echo 7. View computer details
echo 8. View the total disk space and remaining space
echo 9. Remote desktop
echo.

This code outputs some welcome information and menu options for the user to choose from.

set /p num=Please enter options:

This code is used to receive the options entered by the user and store the entered value in the variable "num".

if "%num%"=="1" goto a
if "%num%"=="2" goto b
if "%num%"=="3" goto c
if "%num%"=="4" goto d
if "%num%"=="5" goto e
if "%num%"=="6" goto f
if "%num%"=="7" goto g
if "%num%"=="8" goto h
if "%num%"=="9" goto i
echo 请输入正确的值
pause
goto menu

This code uses conditional judgment statements to jump to the corresponding label based on the options entered by the user to implement the corresponding function. If the option entered by the user is not between 1 and 9, an error message is output and the menu interface is returned.

:a
set /p time=Please enter the time:
shutdown -s -t %time%
echo The scheduled shutdown has been set, thank you for using it!
pause
goto menu

The code at label "a" will prompt the user to enter a time parameter, and then use the `shutdown` command to set the computer to shut down after the specified time. Then display the message of successful setting, pause and return to the menu interface.

:b
ipconfig
pause
goto menu

The code at label "b" will call the `ipconfig` command to display the computer's IP configuration information, then pause and return to the menu interface.

:c
netstat -ano
pause
goto menu

The code at label "c" will call the `netstat` command to display the currently open ports and related information on the computer, then pause and return to the menu interface.

:d
tasklist
pause
echo Press any key to continue!
goto menu

The code at label "d" will call the `tasklist` command to display all processes running on the computer and related information. Then it pauses to display a message, waits for the user to press any key, and finally returns to the menu interface.

. . . . . . Everyone should be able to understand the rest, so I won’t list it here.

2. User operation applet

1.Source code
@echo off
color 5f

title 修改用户小程序
:menu
cls
echo.
echo ============
echo 欢迎使用小程序
echo ============
echo 1.查看用户列表
echo 2.添加用户
echo 3.修改用户密码
echo 4.删除用户
echo 5.激活用户
echo 6.禁用用户
echo 7.退出

echo.
set /p num=请输入选项:
if "%num%"=="1" goto a
if "%num%"=="2" goto b
if "%num%"=="3" goto c
if "%num%"=="4" goto d
if "%num%"=="5" goto e
if "%num%"=="6" goto f
if "%num%"=="7" goto g

echo 请输入正确的值
pause
goto menu
:a
net user
pause
goto menu
:b
set /p user=请输入用户名:
set /p passwd=请输入密码:
net user  %user% %passwd% /add
echo 用户已经设置完毕,谢谢使用!
pause
goto menu
:c
set /p user=请输入用户名:
set /p passwd=请输入新密码:
net user  %user% %passwd% 
echo 密码已经修改完毕,谢谢使用!
pause
goto menu
:d
set /p user=请输入用户名:
net user  %user% /del
echo 用户已经删除完毕,谢谢使用!
pause
goto menu
:e
set /p user=请输入用户名:
net user  %user% /active:yes
echo 用户已经激活完毕,谢谢使用!
pause
goto menu
:f
set /p user=请输入用户名:
net user  %user% /active:no
echo 用户已经禁用完毕,谢谢使用!
pause
goto menu
:g
exit
2. Run screenshot

3.Explain

 @echo off

This line of code means turning off the echo function in the command line, that is, not displaying the command itself when executing the command.

color 5f

This line of code sets the background color and foreground color of the command line window, where the number 5 represents the purple background and the letter f represents the white foreground.

title 修改用户小程序

This line of code sets the title of the command line window to facilitate user identification.

:menu 
cls 
echo. 
echo ============ 
echo Welcome to the mini program 
echo ============ 
echo 1. View the user list 
echo 2. Add user 
echo 3. Modify user password 
echo 4. Delete user 
echo 5. Activate user 
echo 6. Disable user 
echo 7. Exit 
echo. 
set /p num=Please enter the option: 
if "%num%"=="1" goto a 
if "%num %"=="2" goto b 
if "%num%"=="3" goto c 
if "%num%"=="4" goto d 
if "%num%"=="5" goto e 
if " %num%"=="6" goto f 
if "%num%"=="7" goto g 
echo Please enter the correct value 
pause 
goto menu

This part is the core of the entire program. First, it defines a menulabel called , which represents the program's main menu. Then, use clsthe command to clear the screen and make the output information cleaner. Next, use echothe command to output menu options that allow the user to choose which action to perform on the user. After all options are output, use set /pthe command to prompt the user for the number of the selection and assign the value entered by the user to a variable num. After that, use ifthe command to judge the user's input. If it matches a certain option, jump to the corresponding label (for if "%num%"=="1" goto aexample, if the user input is 1, jump to the label a). If the values ​​entered by the user do not meet the requirements, a prompt message is output and the main menu is returned. It should be noted that the goto command is used here to jump to menu options.

:a

net user

pause

goto menu

These lines of code define athe content of the label. Use net userthe command to view the list of users on the current computer, and use pausethe command to pause the running of the program and wait for the user to press any key before continuing. Finally use gotothe command to return to the main menu.

:b
set /p user=请输入用户名:
set /p passwd=请输入密码:
net user  %user% %passwd% /add
echo 用户已经设置完毕,谢谢使用!
pause
goto menu

These lines of code define bthe content of the label. Use set /pthe command to prompt the user for the new user's username and password and save them to the variables userand passwd. Then use net userthe command to create a new user and output the prompt information. Finally use pausethe and gotocommands to return to the main menu.

:c
set /p user=请输入用户名:
set /p passwd=请输入新密码:
net user  %user% %passwd% 
echo 密码已经修改完毕,谢谢使用!
pause
goto menu

These lines of code define cthe content of the label. Use set /pthe command to prompt the user to enter the username and new password for which the password is to be changed, and save them to the variables userand passwd. Then use net userthe command to modify the password of the corresponding user and output the prompt message. Finally use pausethe and gotocommands to return to the main menu.

:d

set /p user=Please enter username:

net user %user% /del

The echo user has been deleted, thank you for using!

pause

goto menu

These lines of code define dthe content of the label. Use set /pthe command to prompt the user for the username to be deleted and save it to the variable user. Then use net userthe command to delete the corresponding user and output the prompt message. Finally use pausethe and gotocommands to return to the main menu.

:e
set /p user=请输入用户名:
net user  %user% /active:yes
echo 用户已经激活完毕,谢谢使用!
pause
goto menu

These lines of code define ethe content of the label. Use set /pthe command to prompt the user for the username to be activated and save it to the variable user. Then use net userthe command to activate the corresponding user and output the prompt message. Finally use pausethe and gotocommands to return to the main menu.

:f
set /p user=Please enter the user name:
net user %user% /active:no
echo The user has been disabled, thank you for using!
pause
goto menu

These lines of code define fthe content of the label. Use set /pthe command to prompt the user for the username to be disabled and save it to a variable user. Then use net userthe command to disable the corresponding user and output a prompt message. Finally use pausethe and gotocommands to return to the main menu.

:g exit

This line of code defines gthe content of the label. Use exitthe command to end the program.

This Windows batch script implements a simple user management function to facilitate users to operate users on the computer.

Guess you like

Origin blog.csdn.net/qq_56698744/article/details/132901232