有时你需要远程管理或运行一批机器,但是按要求你没有权限或者不能安装客户端,下面的批处理可能帮上你的忙,将下方代码保存为批处理,并创建Clients.txt,存放的是以回车分隔的IP
@echo off
setlocal enabledelayedexpansionSet UP=/U username /P password
Set RUN=/run
Set DISABLE=/Change /DISABLE
Set ENABLE=/Change /ENABLE
Set CMD=%DISABLE%:BEGAIN
cls
echo.
echo.
echo ***************远程管理 by Harrell**************
echo.
echo * 1:执行计划任务
echo * 2:禁用计划任务
echo * 3:启用计划任务
echo * 4:结束进程
echo * 5:Ping所有机器
echo * 6:根据XML创建计划任务
echo * 0:退出
echo.
echo *************************************************
echo.
echo.
set /p select=请输入数字:
if %select% == 1 Set CMD=%RUN%
if %select% == 2 Set CMD=%DISABLE%
if %select% == 3 Set CMD=%ENABLE%
if %select% == 4 goto KILL
if %select% == 5 goto PING
if %select% == 6 goto CreateTASK
if %select% == 0 goto END:TASK
if exist "ClientList.txt" (
Echo 输入计划任务名称
Set /p TaskName=
Set SUFFIX=%UP% /TN !TaskName!
Echo 【计划任务】开始执行……
for /f "tokens=1 delims= " %%i in (ClientList.txt) do (
set Client=%%i
echo !Client!
schtasks %CMD% /S !Client! !SUFFIX!
))
pause
goto BEGAIN:CreateTASK
Echo 输入计划任务名称
Set /p TaskName=
Echo 拖入任务xml文件
Set /p Xmlpath=
if exist "ClientList.txt" (
Echo 【计划任务】开始执行……
for /f "tokens=1 delims= " %%i in (ClientList.txt) do (
set Client=%%i
echo !Client!
schtasks /Create /S !Client! %UP% /TN %TaskName% /XML %Xmlpath%
))
pause
goto BEGAIN:KILL
if exist "ClientList.txt" (
Echo 【结束进程】开始执行……
for /f "tokens=1 delims= " %%i in (ClientList.txt) do (
set Client=%%i
echo !Client!
Taskkill /S !Client! %UP% /IM Example.exe /F /T
))
pause
goto BEGAIN:PING
if exist "ClientList.txt" (
Echo 【Ping】开始执行……
for /f "tokens=1 delims= " %%i in (ClientList.txt) do (
set Client=%%i
echo !Client!
Ping -n 1 !Client!>nul
if %errorlevel% NEQ 0 echo 失败
))
pause
goto BEGAIN:END
echo.
echo 退出程序
pause
远程计划任务管理