初始化bat文件
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
::定时同步,如果空闲时间超过30分钟,就同步,否则就什么都不执行
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
set "LOG=%SCRIPT_DIR%autosync.log"
|
||||
set "PS1=%SCRIPT_DIR%get_idle_minutes.ps1"
|
||||
:: 检查 PowerShell 脚本是否存在
|
||||
if not exist "%PS1%" (
|
||||
echo 错误:缺少 get_idle_minutes.ps1
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: 调用 PowerShell 获取空闲分钟数
|
||||
for /f "delims=" %%i in ('powershell -ExecutionPolicy Bypass -File "%PS1%" 2^>nul') do (
|
||||
set "idle_min=%%i"
|
||||
)
|
||||
|
||||
:: 验证是否获取到数字
|
||||
set "is_number=0"
|
||||
for /f "delims=0123456789" %%a in ("%idle_min%") do set "is_number=1"
|
||||
if %is_number% equ 1 (
|
||||
echo [%date% %time%] 无法获取空闲时间,跳过。 >> "%LOG%"
|
||||
exit /b
|
||||
)
|
||||
|
||||
:: 记录日志
|
||||
echo [%date% %time%] 空闲时间: %idle_min% 分钟 >> "%LOG%"
|
||||
|
||||
:: 判断是否 ≥30 分钟
|
||||
if %idle_min% GEQ 30 (
|
||||
echo [%date% %time%] 满足条件,开始同步... >> "%LOG%"
|
||||
|
||||
:: === 你的同步命令 ===
|
||||
:: 注册表路径
|
||||
set "regKey=HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Weasel"
|
||||
|
||||
:: 读取 UninstallString 值
|
||||
for /f "tokens=2*" %%a in ('reg query "%regKey%" /v "UninstallString" 2^>nul ^| findstr /i "UninstallString"') do (
|
||||
set "uninstallCmd=%%b"
|
||||
)
|
||||
|
||||
:: 检查是否找到
|
||||
if not defined uninstallCmd (
|
||||
echo 错误:未找到小狼毫(Weasel)的注册表项。
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: 去掉开头和结尾的引号
|
||||
call set "clean=%%uninstallCmd:"=%%"
|
||||
|
||||
:: 获取上层目录(父目录)
|
||||
for %%I in ("%clean%") do set "apppath=%%~dpI"
|
||||
:: 同步
|
||||
"%apppath%WeaselDeployer.exe" /sync
|
||||
|
||||
:: 暂停30秒,给出同步时间
|
||||
timeout /t 30 /nobreak >nul
|
||||
:: 同步后重新部署
|
||||
"%apppath%WeaselDeployer.exe" /deploy
|
||||
|
||||
echo [%date% %time%] 同步完成。 >> "%LOG%"
|
||||
) else (
|
||||
echo [%date% %time%] 未满足空闲条件,跳过。 >> "%LOG%"
|
||||
)
|
||||
Reference in New Issue
Block a user