- @echo off
-
- if "%~1"=="0" (goto :App0)
- if "%~1"=="1" (goto :App1)
- if "%~1"=="C" (goto :App2)
- if "%~1"=="R" (goto :App3)
-
- start "" %~nx0 0
-
- exit
-
- :App0
- start "" %~nx0 1
- start "" %~nx0 C
- exit
-
- :App1
- title 主
- echo.
- echo.
- echo 嗯,现在是批处理测试ing...
- echo.
- set /p keycode=
- if "%keycode%"=="q" (goto :App4)
- goto :App1
-
- :App2
- title 创建守护VBS...
- ::::::::::::::::::::::::::::::::::::::::::::::::::::
- echo.if Wscript.Arguments.count ^< 1 then >noshut1.vbs
- echo. wscript.quit >>noshut1.vbs
- echo.end if >>noshut1.vbs
- echo.select case ucase(Wscript.Arguments(0)) >>noshut1.vbs
- echo. case "Q" >>noshut1.vbs
- echo. wscript.quit >>noshut1.vbs
- echo. case "R" >>noshut1.vbs
- echo. >>noshut1.vbs
- echo. >>noshut1.vbs
- echo.Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") >>noshut1.vbs
- echo.Set colMonitoredProcesses = objWMIService.ExecNotificationQuery("select * from __instancedeletionevent within 1 where TargetInstance isa 'Win32_Process'") >>noshut1.vbs
- echo.Do While i ^<^> -1 >>noshut1.vbs
- echo.Set objLatestProcess = colMonitoredProcesses.NextEvent >>noshut1.vbs
- echo.if instr(objLatestProcess.TargetInstance.CommandLine,WScript.ScriptName ^& " Q") > 0 then >>noshut1.vbs
- echo. exit do >>noshut1.vbs
- echo.end if >>noshut1.vbs
- echo.for i=1 to Wscript.Arguments.count-1 >>noshut1.vbs
- echo. if instr(objLatestProcess.TargetInstance.CommandLine,Wscript.Arguments(i)) > 0 then >>noshut1.vbs
- echo. '结束的进程是被守护进程i,则启动 >>noshut1.vbs
- echo. if instr(wscript.arguments(i)," 1") > 0 then >>noshut1.vbs
- echo. Wscript.createobject("wscript.shell").run replace(objLatestProcess.TargetInstance.CommandLine," 1"," R"),1 >>noshut1.vbs
- echo. else >>noshut1.vbs
- echo. Wscript.createobject("wscript.shell").run objLatestProcess.TargetInstance.CommandLine,1 >>noshut1.vbs
- echo. end if >>noshut1.vbs
- echo. end if >>noshut1.vbs
- echo.next >>noshut1.vbs
- echo.Loop >>noshut1.vbs
- echo.wscript.sleep 3000 >>noshut1.vbs
- echo.wscript.quit >>noshut1.vbs
- echo.end select >>noshut1.vbs
- ::::::::::::::::::::::::::::::::::::::::::::::::::::
- copy noshut1.vbs noshut2.vbs
- start wscript.exe //nologo noshut1.vbs R "%~nx0 1" "%~nx0 R" "noshut2.vbs R"
- start wscript.exe //nologo noshut2.vbs R "noshut1.vbs R"
- exit
-
- :App3
- title 被关闭后,重新运行
- echo 哈哈,我又运行了!
- pause>nul
- goto :App1
-
- :App4
- title 带参数启动守护VBS,使其结束自身
- start wscript.exe //nologo noshut1.vbs Q
- start wscript.exe //nologo noshut2.vbs Q
- ping.exe 127.1 -n 15 >nul 2>nul
- del noshut1.vbs /f /q /a >nul 2>nul
- del noshut2.vbs /f /q /a >nul 2>nul
- exit
复制代码
似乎第三条,被Kill后不同的提示,这个没法做,只能和被结束一起处理
嘿嘿,2个VBS互相守护
一个看着 bat 和另一个 vbs
另一个只管 第一个vbs |