win2003系统管理脚本
最近没什么事做,把以前写的小脚本发出来看看,
主要是可以定时关机,查看进程检测软件包的简单脚本。
@echo off
:menu
cls
title 系统管理小程序
echo ================
echo 菜单
echo 1.定时关机
echo 2.查看本机IP
echo 3.查看守护进程
echo 4.查看进程和处理进程
echo 5.检查软件包是否安全
echo 6.退出
echo ================
set /p num=请输入选项:
if "%num%"=="1" goto a
if "%num%"=="2" goto b
if "%num%"=="3" goto debate
if "%num%"=="4" goto _jinchen
if "%num%"=="5" goto Package
if "%num%"=="6" goto c
echo 请正确输入数值(1、2、3、4、5、6),按任意键继续!
pause
goto menu
:_jinchen
echo ------进程处理开始------
tasklist > list.txt
set /p _kill=请输入要杀死的进程id:
find /i "%_kill%" list.txt
if "%errorlevel%"=="1" (goto _start) else (goto _killj)
:_killj
taskkill /f /pid "%_kill%"
echo 处理完成
echo %_interval%秒后返回菜单......
choice /t %_interval% /d y /n >nul
goto menu
:_start
echo 该进程不存在
echo 是否继续,1为继续,其他返回菜单
set /p _be1 = 1/0:
if "%_be1%" == "1" (goto jinchen) else (goto menu)
:a
set /p time=请输入时间:
shutdown -s -f -t %time%
echo 定时关机已设置完毕,按任意键返还菜单!
pause
goto menu
:b
ipconfig
echo 按任意键返还菜单!
pause
goto menu
:debate
set d=%date:~0,10%
set d=%d: =0%
echo %d%
set logFile=.\processWatch_%d:-=%.txt
echo 现在时间:%date%%time%
echo ********程序开始启动******** >> %logFile%
set runAppPath=%1
set runAppPath="C:\Documents and Settings\Administrator\桌面\RSATool2v17.exe"
set runAppFolder=''
if '%runAppPath%'=='' (goto end)
set _processName=''
set _processNameExt=''
::检测时间间隔,单位:秒
set _interval=5
for %%a in (%runAppPath%) do (
set _processName=%%~na
set _processNameExt=%%~nxa
set runAppFolder=%%~dpa
)
goto checkstart
rem 以下是测试代码
echo %_processName%
echo %_processNameExt%
echo %runAppFolder%
echo %runAppPath%
echo ====================================================
pause
goto end
:checkstart
set d=%date:~0,10%
set d=%d: =0%
set logFile=.\processWatch_%d:-=%.txt
for /f "tokens=1" %%n in ('tasklist.exe ^| find /I "%_processNameExt%" ') do (
if '%%n'=='%_processNameExt%' (echo 检查进程【%_processNameExt%】正在运行 >> %logFile% && goto checkend) )
echo 检查进程【%_processNameExt%】未在运行 >> %logFile%
:startApp
echo, && echo ********开始启动程序********
echo ********开始启动程序******** >> %logFile%
echo [%date:~0,10%%time:~0,8%] 未检测到【%_processNameExt%】的进程,将重新启动程序 >> %logFile%
echo [%date:~0,10%%time:~0,8%] 重新启动程序:%runAppPath%
echo [%date:~0,10%%time:~0,8%] 重新启动程序:%runAppPath% >> %logFile%
echo 开始执行 start "" %runAppPath% >> %logFile%
pushd %runAppFolder%
start "" %runAppPath%
popd
echo ********启动程序完成******** && echo,
echo ********启动程序完成******** >> %logFile%
echo, >> %logFile%
:checkend
echo [%date:~0,10%%time:~0,8%] 程序【%_processNameExt%】运行正常,%_interval%秒后返回菜单......
choice /t %_interval% /d y /n >nul
goto end
:end
echo end.
goto menu
:Package
echo ------软件包校验开始------
set /p _package1=请输入要校验的非官网的软件包地址:
set /p _package2=请输入要校验的官网的软件包地址:
setlocal enabledelayedexpansion
set /a row=0
for /f "tokens=*" %%i in ('CertUtil -hashfile %_package1% MD5') do (
set /a row+=1
if !row!==2 set md51=%%i)
set /a row1=0
for /f "tokens=*" %%i in ('CertUtil -hashfile %_package2% MD5') do (
set /a row1+=1
if !row1!==2 set md52=%%i)
set md51=%md51%
set md52=%md52%
set /a row2=0
for /f "tokens=*" %%i in ('CertUtil -hashfile %_package1% SHA256') do (
set /a row2+=1
if !row2!==2 set sha1=%%i)
set /a row3=0
for /f "tokens=*" %%i in ('CertUtil -hashfile %_package2% SHA256') do (
set /a row3+=1
if !row3!==2 set sha2=%%i)
set sha1=%sha1%
set sha2=%sha2%
echo %md51%
echo %md52%
pause
goto start_package
::检查软件包如否安全
:start_package
echo ---------开始校验---------
echo 1:MD5
echo 2:SHA256
echo 0:返回
set /p key=选择校验方式:
if "%key%" equ "1" goto md512
if "%key%" equ "2" goto sha256a
if "%key%" equ "0" goto start_package
:md512
echo 123
pause
if "%md51%" == "%md52%" (
echo 软件没有问题
pause
goto _yiwen)
if "%md51%" neq "%md52%" (
echo 该软件有毛病
pause
goto menu
)
:sha256a
if "%sha1%" == "%sha2%" (echo 软件没有问题
pause
goto _yiwen)
if "%sha1%" neq "%sha2%" (
echo 该软件有毛病
pause
goto menu
)
:_yiwen
cls
echo 是否继续校验,1为继续,其他返回菜单
set /p num1=输入:
echo %num1%
if %num1% equ 1 (goto Package)
if %num1% equ 0 (echo %_interval%秒后返回菜单......
choice /t %_interval% /d y /n >nul
goto menu)
:c
exit