Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Auto Restart Folding@Home
Name: Auto Restart Folding@Home
Author: Bryan Vine
Date: 3/25/2020
Description: Automatically restarts the local Folding @ Home client while cleaning out existing work to reset the connection countdown timer based on CPU & GPU usage.
#Requires -Version 3.0
$restart_counter = 1
#Loop forever
$CPU_usage = (Get-Counter '\Processor(_Total)\% Processor Time').countersamples.cookedvalue
$GPU_usage = (Get-Counter -Counter "\GPU Engine(*)\Utilization Percentage").countersamples.cookedvalue | sort -Descending | select -first 1
"$(Get-Date) - CPU usage: $([math]::Round($CPU_usage,0))%, GPU usage: $([math]::Round($GPU_usage,0))%"
#Resets if CPU or GPU are under 20%
if($CPU_usage -lt 20 -or $GPU_usage -lt 20){
"CPU and GPU idle, restarting F@H for the $restart_counter time"
if(Get-Service -name "*Folding@Home*"){
Get-Service -name "*Folding@Home*" | Stop-Service -Verbose
Get-Process -Name FAHClient -ErrorAction SilentlyContinue| Stop-Process -Verbose
Start-Sleep -Seconds 3
if(!(dir "C:\Users\$($env:USERNAME)\AppData\Roaming\FAHClient\work\" -directory)){
Remove-Item "C:\Users\$($env:USERNAME)\AppData\Roaming\FAHClient\work\client.db*" -Force -Verbose
if(Get-Service -name "*Folding@Home*"){
Get-Service -name "*Folding@Home*" | Start-Service -Verbose
Write-Verbose "Started FAHClient Service" -Verbose
cd "C:\Users\$($env:USERNAME)\AppData\Roaming\FAHClient"
. "C:\Program Files (x86)\FAHClient\HideConsole.exe" "C:\Program Files (x86)\FAHClient\FAHClient.exe"
Write-Verbose "Started FAHClient" -Verbose
#wait 5 minutes
Start-Sleep -Seconds 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment