本帖最后由 n0b0dy 于 2025-5-27 05:13 编辑
# Changelog
## 2025-05-26
### Changed
- 优化了计划任务的运行条件:
- 在使用电池的情况下也可运行计划任务
- 仅在连接网络时运行计划任务
- 若错过预定运行时间,计划任务将在系统下一次登录后补运行
- @echo off
- REM Set the current directory
- cd /d "%~dp0"
- REM Step 1: Get admin rights
- NET FILE 1>NUL 2>NUL
- if '%errorlevel%' == '0' ( goto :gotAdmin ) else ( powershell Start-Process '%0' -Verb runAs & exit /B )
- :gotAdmin
- REM Step 2: Get version information from startup.exe
- setlocal EnableDelayedExpansion
- for /f "usebackq delims=" %%i in (`powershell -command "& {(Get-Item '.\startup.exe').VersionInfo.ProductVersion}"`) do (
- set "fullversion=%%i"
- )
- REM Extract just the first two segments (e.g., 21.20 from 21.20.8.505)
- for /f "tokens=1,2 delims=." %%a in ("!fullversion!") do (
- set "majorversion=%%a.%%b"
- )
- echo Detected Kaspersky version: !majorversion!
- REM Step 3: Ask user to choose
- :autoRenewal
- echo.
- echo Would you like to enable automatic license renewal?
- set /p renewal="Enter your choice (y/n): "
- if "%renewal%"=="y" (
- goto :editionSelection
- ) else if "%renewal%"=="n" (
- goto :installation
- ) else (
- echo Invalid choice.
- goto :autoRenewal
- )
- :editionSelection
- echo.
- echo Please select Kaspersky edition:
- echo 1. Standard
- echo 2. Plus
- echo 3. Premium
- echo.
- set /p edition="Enter your choice (1-3): "
- if "%edition%"=="1" (
- set "editionName=Kaspersky Standard"
- set "licenseKey=GAJPU-UTD18-3B2JJ-62CQ2"
- ) else if "%edition%"=="2" (
- set "editionName=Kaspersky Plus"
- set "licenseKey=GE86F-9WQRM-KK5PG-1ZE2W"
- ) else if "%edition%"=="3" (
- set "editionName=Kaspersky Premium"
- set "licenseKey=5AP55-UFAT1-QUMNN-7CUDZ"
- ) else (
- echo Invalid choice.
- goto :editionSelection
- )
- echo.
- echo Selected edition: %editionName%
- :installation
- REM Step 4: Run "startup.exe" without self protection
- echo.
- echo Installing Kaspersky with self protection disabled...
- start "" startup.exe /pSelfProtection=0
- REM Step 5: Monitor registry key and modify values during installation
- echo.
- echo Monitoring and updating registry values...
- :checkRegistry
- REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\KasperskyLab\AVP%majorversion%\environment" /v "ProductStatus" >nul 2>&1
- if %errorlevel% equ 0 (
- echo Registry found, applying modifications...
- REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\KasperskyLab\AVP%majorversion%\environment" /v "ProductStatus" /t REG_SZ /d "" /f >nul 2>&1
- echo Registry modifications completed.
- goto :setupTask
- ) else (
- goto :checkRegistry
- )
- :setupTask
- if "%renewal%"=="n" (
- goto :done
- )
- REM Step 6: Manage scheduled task for license renewal
- :search
- REM Clear previous value
- set "avp="
- REM Search for avp.com under Kaspersky Lab directory
- for /f "delims=" %%A in ('dir /b /s /a-d "C:\Program Files (x86)\Kaspersky Lab\avp.com" 2^>nul') do (
- set "avp=%%A"
- )
- if not defined avp (
- timeout /t 5 >nul
- goto :search
- )
- echo.
- echo Found avp.com at: %avp%
- echo Creating new license renewal task to run every 28 days...
- set "taskname=Kaspersky License Renewal"
- set "xmlfile=%TEMP%\task.xml"
- REM Creating new license renewal task...
- schtasks /create /tn "%taskname%" /tr "\"%avp%\" LICENSE /add %licenseKey%" /sc DAILY /mo 28 /f >nul 2>&1
- REM Exporting the task to XML...
- schtasks /query /tn "%taskname%" /xml > "%xmlfile%"
- REM Modifying XML settings...
- REM Use PowerShell to update XML
- powershell -Command ^
- "$xml = [xml](Get-Content '%xmlfile%');" ^
- "$nsmgr = New-Object System.Xml.XmlNamespaceManager($xml.NameTable);" ^
- "$nsmgr.AddNamespace('ns', $xml.DocumentElement.NamespaceURI);" ^
- "$settings = $xml.SelectSingleNode('//ns:Settings', $nsmgr);" ^
- "if (-not $settings) { $settings = $xml.CreateElement('Settings', $xml.DocumentElement.NamespaceURI); $xml.Task.AppendChild($settings) | Out-Null };" ^
- "if (-not $settings.SelectSingleNode('ns:StartWhenAvailable', $nsmgr)) {" ^
- "$node = $xml.CreateElement('StartWhenAvailable', $xml.DocumentElement.NamespaceURI);" ^
- "$node.InnerText = 'true'; $settings.AppendChild($node) | Out-Null" ^
- "} else { $settings.SelectSingleNode('ns:StartWhenAvailable', $nsmgr).InnerText = 'true' };" ^
- "if (-not $settings.SelectSingleNode('ns:DisallowStartIfOnBatteries', $nsmgr)) {" ^
- "$node = $xml.CreateElement('DisallowStartIfOnBatteries', $xml.DocumentElement.NamespaceURI);" ^
- "$node.InnerText = 'false'; $settings.AppendChild($node) | Out-Null" ^
- "} else { $settings.SelectSingleNode('ns:DisallowStartIfOnBatteries', $nsmgr).InnerText = 'false' };" ^
- "if (-not $settings.SelectSingleNode('ns:RunOnlyIfNetworkAvailable', $nsmgr)) {" ^
- "$node = $xml.CreateElement('RunOnlyIfNetworkAvailable', $xml.DocumentElement.NamespaceURI);" ^
- "$node.InnerText = 'true'; $settings.AppendChild($node) | Out-Null" ^
- "} else { $settings.SelectSingleNode('ns:RunOnlyIfNetworkAvailable', $nsmgr).InnerText = 'true' };" ^
- "$xml.Save('%xmlfile%')" >nul 2>&1
- REM Re-importing modified task...
- schtasks /delete /tn "%taskname%" /f >nul 2>&1
- schtasks /create /tn "%taskname%" /xml "%xmlfile%" /f >nul 2>&1
- del "%xmlfile%" 2>nul
- echo Task updated successfully.
- echo.
- echo Activating %editionName%...
- :checkStartup
- REM Check if avp.exe is running
- tasklist | find /i "avp.exe" >nul 2>&1
- if %errorlevel% neq 0 (
- timeout /t 5 >nul 2>&1
- goto :checkStartup
- )
- schtasks /run /tn "%taskname%"
- echo.
- echo Selected edition: %editionName%
- echo Using version: %majorversion%
- echo License key: %licenseKey%
- :done
- echo Process completed successfully.
- endlocal
- timeout /t 10
复制代码 |