Board logo

标题: [其他] bat如何定时关闭 [打印本页]

作者: jjss520    时间: 2019-8-23 08:52     标题: bat如何定时关闭

个人需要循环点击手机音量键就百度加上自己修改了这个代码,代码可以循环的点击音量键
但现在定时关闭,比如设置半小时后自动关闭该批处理
请问各位大神,应该怎么加,菜鸟一个,论坛搜索也没得到答案
谢谢
  1. @echo off
  2. :one
  3. ::adb shell input swipe 900 1000 700 1000
  4. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  5. ping -n 6 127.0.0.1>nul
  6. goto two
  7. :two
  8. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  9. ping -n 6 127.0.0.1>nul
  10. goto one
复制代码

作者: 窄口牛    时间: 2019-8-23 10:51

exit或者taskkill /im cmd.exe /f
作者: jjss520    时间: 2019-8-26 11:16

回复 2# 窄口牛


    怎么定时半小时结束呢,请教
作者: jjss520    时间: 2019-8-26 11:21

@echo off
ne
::adb shell input swipe 900 1000 700 1000
adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
ping -n 6 127.0.0.1>nul
goto two

:two
adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
ping -n 6 127.0.0.1>nul
goto one

ping localhost -n 1800 > nul&taskkill /f /im cmd.exe

这样加在后面,这段命令不会运行
前面两段命令,一直在重复,怎么设这个半小时结束的命令生效呢
作者: flashercs    时间: 2019-8-26 14:21

  1. @echo off
  2. REM timelimit是半小时期限,单位是10ms
  3. set /a timelimit=180000
  4. call :getTod time_1
  5. :one
  6. ::adb shell input swipe 900 1000 700 1000
  7. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  8. ping -n 6 127.0.0.1>nul
  9. goto two
  10. :two
  11. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  12. ping -n 6 127.0.0.1>
  13. call :getTod time_2
  14. set /a "time_dist=time_2-time_1"
  15. if %time_dist% LSS 0 set /a "time_dist+=8640000"
  16. if %time_dist% lss %timelimit% (
  17.   goto one
  18. )
  19. exit /b
  20. :getTod -- get a Time of Day value in 1/100th seconds
  21. ::   -- %~1: out - time of day
  22. SETLOCAL
  23. set t=%time: =0%
  24. set /a t=((1%t:~0,2%*60+1%t:~3,2%)*60+1%t:~6,2%)*100+1%t:~9,2%-36610100
  25. ( ENDLOCAL & REM RETURN VALUES
  26.     IF "%~1" NEQ "" SET %~1=%t%
  27. )
  28. GOTO:EOF
复制代码

作者: jjss520    时间: 2019-8-26 16:15

回复 5# flashercs


    老大,代码好像不太对,打开过一会儿就关了
作者: flashercs    时间: 2019-8-26 16:57

回复 6# jjss520


    第14行:改为ping -n 6 127.0.0.1>nul
作者: 窄口牛    时间: 2019-8-26 19:38

  1. @echo off
  2. echo @echo off>>%temp%\run.bat
  3. echo :1>>%temp%\run.bat
  4. echo adb shell input keyevent 25 %%KEYCODE_VOLUME_DOWN%%>>%temp%\run.bat
  5. echo ping -n 6 127.0.0.1^>nul>>%temp%\run.bat
  6. echo goto ^1>>%temp%\run.bat
  7. start "" %temp%\run.bat
  8. timeout /t 1800 /nobreak
  9. taskkill /f cmd.exe /im
复制代码

作者: h503mc    时间: 2019-8-28 17:35

  1. @echo off
  2. if "%1"=="deamon" goto deamon
  3. set TempFile=%TEMP%\sthUnique.tmp
  4. wmic process where (Name="wmic.exe" AND CommandLine LIKE "%%%TIME%%%") get ParentProcessId /value | find "ParentProcessId" >%TempFile%
  5. set /P _string=<%TempFile%
  6. set _pid=%_string:~16%
  7. echo %_pid% >pid.txt
  8. goto start
  9. :deamon
  10. @echo off
  11. set /p ppid=<pid.txt
  12. del pid.txt
  13. ping 127.1 /n 1801 >nul
  14. taskkill /f /pid %ppid%
  15. exit
  16. :start
  17. start /min "" %0 deamon
  18. :one
  19. ::adb shell input swipe 900 1000 700 1000
  20. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  21. ping 127.1 /n 6 >nul
  22. goto two
  23. :two
  24. adb shell input keyevent 25 %KEYCODE_VOLUME_DOWN%
  25. ping 127.1 /n 6 >nul
  26. goto one
复制代码
已测试,先告知子程序pid,在杀进程.




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2