Home  >  Article  >  Operation and Maintenance  >  Use bat batch file to operate windows example code

Use bat batch file to operate windows example code

零下一度
零下一度Original
2017-05-24 14:57:212586browse

A bat batch file that implements starting the windows process and delaying the shutdown. It is used to open and close IE. Friends who learn batch processing can refer to it.

A few days ago, the leader asked us to vote on the website to improve his ranking, but each person's vote only amounted to more than 100 votes. A few days later, my boss asked me if I would create a vote-swiping program to improve my ranking. I said I could give it a try. After researching for a day, I finally made it. I was so excited that I couldn't sleep all night. Now take it out and share it.
To put it bluntly, what I made is actually a batch file. The batch extension is .bat. In fact, the voting page only uses session to control whether to vote. As we all know, the session variable will automatically disappear after IE is closed and reopened. A new connection will be created when the page is opened, so you can vote again. This page uses AJAX. I found the JS where ajax is located, found out its real voting page, and passed the ID through the page to implement voting. What we need to do now is to automatically open the IE connection voting page, then automatically disconnect and automatically reconnect, thereby achieving repeated voting.
This voting website has two fatal points. One is that voting is not controlled by IP but is controlled by the session server, which results in repeated voting with one IP. Second, the parameters of the actual voting processing page are transmitted through GET. This This will lead to the possibility of cheating.
By exploiting the above two vulnerabilities, I also made a bat batch process, as follows:

The code is as follows:

@
echo
 off 
echo 正在关闭冗余进程,请稍等...... 
taskkill /f /im iexplore.exe 
echo -------------程序初始化完毕,请指示!---------- 
echo. & pause 
:openie 
echo 正在投票,请稍等...... 
start "" "C:\Program 
File
s\Internet Explorer\iexplore.exe" 
echo IE打开完成! 
ping 127.0.0.1 -n 2 
taskkill /f /im iexplore.exe 
echo 延时2秒关闭投票完成! 
goto
 openie 
echo. & pause

Explanation of key points:
taskkill /f /im iexplore .exe forcibly closes the IE process. Of course, it can also close other processes. The process name can be found through the task manager.
start "" "C:\Program Files\Internet Explorer\iexplore.exe" This is to open a windows program, pay attention to the path, and be sure not to lose the "" after start.
ping 127.0.0.1 -n 2 Use this to delay. Everyone knows that delayed execution of bat batch processing is too troublesome. This is simpler. It should be noted that you must ping the local 127.0.0.1, otherwise It may lead to different timing lengths. -n 2 means repeating twice, which is about 2 seconds. Of course, the duration is adjustable, just adjust the number.
Key point: infinite loop of bat batch processing. :openie means to set a point. This can be arbitrary. Any combination of letters will do. Do not repeat keywords. goto openie means to return to the point openie set previously. The set return points must correspond to each other.

Now you can copy the above code into a text document. Be sure to change the extension to .bat. .bat is the standard extension for batch processing. Of course, a very classic program of 98 is autoexec.bat. I believe many people who have come here have heard of it. If you are interested, you can search it on Baidu. Of course, you can also start or end the processes of other programs by analogy.
If you have any questions, you can ask me. The QQ number is on the right side at the bottom of the page. Let’s improve together and make progress together. Haha
The following program was found online. You can copy it to know exactly what it does. In some places, I don’t understand. If you have high comprehension ability, study it yourself!
Tips: The following program monitors whether a process exists. If it does not exist, it will start. If the process is lost, it will also start, which means the program will run forever!

The code is as follows:

@echo off 
set
 _task=notepad.exe 
set _svr=c:\windows\notepad.exe 
set _des=start.bat 
:checkstart 
for
 /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do ( 
if
 %%n==%_task% (goto checkag) 
else
 goto startsvr 
) 
:startsvr 
echo %
time
% 
echo ********程序开始启动******** 
echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.txt 
echo start %_svr% > %_des% 
echo exit >> %_des% 
start %_des% 
set/p=.<nul 
for /L %%i in (1 1 10) do set /p a=.<nul&ping.exe /n 2 127.0.0.1>nul 
echo . 
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs 
cscript //b //nologo %tmp%\delay.vbs 10000 
del %_des% /Q 
echo ********程序启动完成******** 
goto checkstart 
:checkag 
echo %time% 程序运行正常,10秒后继续检查.. 
echo Wscript.Sleep WScript.Arguments(0) >%tmp%\delay.vbs 
cscript //b //nologo %tmp%\delay.vbs 10000 
goto checkstart

[Related recommendations]

1. Steps to build a Java development environment under Windows 7 (illustration)

2. Install Ulipad editor under Windows system

3. Use Python to develop windows desktop programs

4. Teach you how to install python2 and python3 versions in Windows environment

The above is the detailed content of Use bat batch file to operate windows example code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn