Skip to content

Instantly share code, notes, and snippets.

@ElGuillermo
Created October 13, 2023 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ElGuillermo/6c05bf4890ce6c80ce770b2e425074ab to your computer and use it in GitHub Desktop.
Save ElGuillermo/6c05bf4890ce6c80ce770b2e425074ab to your computer and use it in GitHub Desktop.
[Windows] Un script batch pour reprendre les tâches Boinc suspendues
@echo off
setlocal enableextensions EnableDelayedExpansion
rem Settings
rem ==============================================================
rem Defines the url of the project we want the tasks to be resumed
set ResumeProjectUrl=https://wuprop.boinc-af.org/
rem ==============================================================
rem Defines the path to the client_state.xml Boinc file
set ClientStateFile=%ProgramData%\BOINC\client_state.xml
rem Defines the path to the boinccmd.exe
set BoincCmdFile=%ProgramFiles%\BOINC\boinccmd.exe
rem This is real content, extracted from client_state.xml
rem (useful to have a quick reference)
rem <project_master_url>https://wuprop.boinc-af.org/</project_master_url>
rem <result_name>data_collect_v4_1490525102_609550_0</result_name>
rem <active_task_state>1</active_task_state>
rem Find the lines that contains a specific string... "project_master_url" seems OK (1st line in the above example)
for /f "delims=:" %%I in ('findstr.exe /I /L /N /C:"project_master_url" "%ClientStateFile%" 2^>nul') do (
rem assign variables :
rem a is the first line number, containing <project_master_url>value</project_master_url>
rem b is the next line number, containing <result_name>value</result_name>
rem c is the next line number, containing <active_task_state>value</active_task_state>
set /a a=%%I
set /a b=a+1
set /a c=a+2
rem As we want to resume only a specific project WUs, let's evaluate the url first
rem read first line (a)
for /f "tokens=1* delims=]" %%A in ('^<"%ClientStateFile%" FIND /N /V "" ^| FINDSTR /B /C:"[!a!]"') do (
rem extract project_master_url value (between <tag></tag>)
rem %%a is opening tag, %%b is the value, %%c is closing tag
for /f "tokens=2-4delims=<>" %%a in ("%%B") do (
rem Let's compare the project_master_url value and the desired url (in Settings)
if "%ResumeProjectUrl%"=="%%b" (
rem If values are the same let's find if <active_task_state> is 0 (suspended)
rem Read third line (c)
for /f "tokens=1* delims=]" %%A in ('^<"%ClientStateFile%" FIND /N /V "" ^| FINDSTR /B /C:"[!c!]"') do (
rem extract active_task value (between <tag></tag>)
rem %%a is opening tag, %%b is the value, %%c is closing tag
for /f "tokens=2-4delims=<>" %%a in ("%%B") do (
rem Value is 0 (suspended)
if "%%b"=="0" (
rem Read second line (b)
for /f "tokens=1* delims=]" %%A in ('^<"%ClientStateFile%" FIND /N /V "" ^| FINDSTR /B /C:"[!b!]"') do (
rem extract result_name value (between <tag></tag>)
rem %%a is opening tag, %%b is the value, %%c is closing tag
for /f "tokens=2-4delims=<>" %%a in ("%%B") do (
rem let's call the boinccmd executable to resume the task
start "Resuming" /B "%BoincCmdFile%" --task %ResumeProjectUrl% %%b resume
)
)
)
rem if "%%b" NEQ "0" (
rem echo "Good project, but the task is active"
rem )
)
)
)
rem if "%ResumeProjectUrl%" NEQ "%%b" (
rem echo "Other project"
rem )
)
)
rem clear variables
set a=
set b=
set c=
)
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment