Our Little Milestone – Folding@home

This is how I implement it

The default code I’ve copied at the end and is between the two lines of asterisks. I have customised the top bit as follows so that it can use my team and another one of my jokey names. Like so:

You will see that I’ve ignored the -switch suggestion and instead just copied the needed lines, remmed out the username and team strings with a hash at the start of each line (#) and then changed the username and team to my own. You could do the same or similar or just leave it and give all credit to the six creators of the code. I have chosen myself as it’s my electricity and my machine that is being contributed to the project.

If you’ve never done any code before, now is a good time to giving it a shot. You’ll see that my changes aren’t exactly hard or rocket science, but when you’ve done it and after it works you can give yourself a little pat for your first bit of customising!!

So, the below, to re-iterate, is between the asterisks and is the code as it stood on the 10th April 2020. Bleeping Computer has a similar install without a hard-coded path. In his case the batch file needs to be in the same folder as the ps1 script – if not you get an error.

  • Click the “RAW” button and copy all of the text from the raw page
  • Paste all of the text into a blank Notepad
  • Save the file with the name they use (not actually necessary, but it keeps things simple). For ease, save the file on your C:\ drive. The full file path will thus be: C:\install_folding_sandbox_on_host.ps1
  • Now create a batch file. It will have one line in it. So open another blank notepad.
  • Paste this into the blank notepad page – Powershell.exe -ExecutionPolicy Bypass -File C:\install_folding_sandbox_on_host.ps1 It MUST be all on one line!
  • Now save the Notepad as this InstallSandboxFoldingAtHome.bat Save it to your desktop for ease of access. You can call it what you want, of course.

Now to run the whole shebang you just right-click on InstallSandboxFoldingAtHome.bat and select Run as administrator as I’ve highlighted in my screenshot below.

I have a 4GHz machine with 16Gb of memory running off a 500Gb SSD. It took well under a minute for the whole thing to go from a cold start. Your mileage may vary. If you follow my method the only error you will probably get is if Virtualization isn’t enable in the BIOS of your machine. The script can’t do this for you and you’ll have to enable it manually OR your machine can not run virtual machines – some can’t but many can nowadays.

This is the scripted installation all running in the automatically created Windows Sandbox. If I can do it, then anybody can!!!


#Requires -RunAsAdministrator

#For a custom username, add -username <your username> to the command execution
  [string]$username = 'wsandbox_anon',
  [string]$team     = '251561'
$ProgressPreference = 'SilentlyContinue' #Progress bar makes things way slower

# Ensure that virtualization is enbaled in BIOS.
Write-Output 'Verifying that virtualization is enabled in BIOS...'
if ((Get-CimInstance Win32_ComputerSystem).VirtualizationFirmwareEnabled -eq $false) {
	Write-Output 'ERROR: Please Enable Virtualization capabilities in your BIOS settings...'

# Ensure that virtualization is enbaled in Windows 10.
Write-Output 'Verifying that virtualization is enabled in Windows 10...'
if ((Get-CimInstance Win32_ComputerSystem).HypervisorPresent -eq $false) {
	Write-Output 'ERROR: Please Enable Hyper-V in your Control Panel->Programs and Features->Turn Windows features on or off'

# Determine if Windows Sandbox is enabled.
	Write-Output 'Checking to see if Windows Sandbox is installed...'
	If ((Get-WindowsOptionalFeature -FeatureName 'Containers-DisposableClientVM' -Online).State -ne 'Enabled') {
		Write-Output 'Windows Sandbox is not installed, attempting to install it (may require reboot)...'
		if ((Enable-WindowsOptionalFeature -FeatureName 'Containers-DisposableClientVM' -All -Online -NoRestart).RestartNeeded) {
			Write-Output 'Please reboot to finish installing Windows Sandbox, then re-run this script...'
	} else {
		Write-Output 'Windows Sandbox already installed.' 
	Write-Output 'ERROR: Please Enable Virtualization capabilities in your BIOS settings ,then re-run this script...'

# Download the latest version of FAH.
Write-Output 'Checking for latest version of foldingathome...'
$installer_url = 'https://download.foldingathome.org/releases/public/release/fah-installer/windows-10-32bit/'

# Use regex to get the latest version from the FAH website.
$version = ((Invoke-WebRequest -Uri $installer_url -UseBasicParsing).Links | Where-Object  {$_.href -match '^v\d+([.]\d+)?'} | ForEach-Object {[float]($_.href -replace '[^.\d]', '')} | Measure-Object -Max).Maximum
$installer = "$($installer_url)v$($version)/latest.exe"
$installer_size =(Invoke-WebRequest $installer -Method Head -UseBasicParsing).Headers.'Content-Length'
Write-Output "Using FAH v$version."

# Check if the installer is present, download otherwise.
$working_dir = "$env:USERPROFILE\fah_conf"
$install_fname = 'folding_installer.exe'
If (!(test-path "$working_dir\$install_fname") -or (Get-ChildItem "$working_dir\$install_fname").Length -ne $installer_size ) {
	Remove-Item "$working_dir\$install_fname" -Force -ErrorAction SilentlyContinue
	Write-Output "Downloading latest folding executable: $working_dir\$install_fname"
	Write-Output "Saving to $working_dir\$install_fname..."
	New-Item -ItemType Directory -Force -Path $working_dir | Out-Null
	Invoke-WebRequest -Uri $installer -OutFile "$working_dir\$install_fname"

# Create the FAH configuration file with the Windows Sandbox FAH team #251561.
Write-Output 'Creating init command...'
$conf_file = 'fah_sandbox_conf.xml'
Write-Output "Saved Folding@Home configuration file to $working_dir\$conf_file"
New-Item -Force -Path "$working_dir\$conf_file" -ItemType File
Set-Content -Path "$working_dir\$conf_file" -Value @"
  <user v='$username'/>
  <team v='$team'/>
  <core-priority v='low'/>
  <power v='full' />
  <priority v='realtime'/>
  <smp v='true'/>
  <gpu v='true'/>
  <open-web-control v='true'/>

Create the script that runs at logon. This script:
	1. Starts the installer
	2. Creates a volatile working directory
	3. Copies the config into the working directory
	4. Sets the firewall policies to let FAH run
	5. Starts the FAH client
Write-Output 'Creating init command...'
$logon_cmd = "$working_dir\init.cmd"
$wdg_install_dir = 'C:\users\wdagutilityaccount\desktop\fah_conf'
$wdg_working_dir = 'C:\users\wdagutilityaccount\desktop\fah_working_dir'
Write-Output "Saved logon script to $logon_cmd, this will be run upon starting Sandbox."
New-Item -Force -Path $logon_cmd -ItemType File
Set-Content -Path $logon_cmd -Value @"
start $wdg_install_dir\$install_fname /S

if exist "C:\Program Files (x86)\FAHClient\FAHClient.exe" goto INSTALLCOMPLETE
ping -n 6 > nul

mkdir $wdg_working_dir
cd $wdg_working_dir
echo \"Copying config file to $wdg_working_dir\"
copy $wdg_install_dir\$conf_file $wdg_working_dir
netsh advfirewall firewall Add rule name="FAHClient" program="C:\Program Files (x86)\FAHClient\FAHClient.exe" action=allow dir=out
netsh advfirewall firewall Add rule name="FAHClient" program="C:\Program Files (x86)\FAHClient\FAHClient.exe" action=allow dir=in
start C:\"Program Files (x86)"\FAHClient\FAHClient.exe --config $wdg_working_dir\$conf_file

# Create the Sandbox configuration file with the new working dir & LogonCommand.
$sandbox_conf = "$working_dir\fah_sandbox.wsb"
Write-Output "Creating sandbox configuration file to $sandbox_conf"
New-Item -Force -Path $sandbox_conf -ItemType File
Set-Content -Path $sandbox_conf -Value @"

# For convenience, start the Sandbox.
Write-Output 'Starting sandbox...'
Start-Process 'C:\WINDOWS\system32\WindowsSandbox.exe' -ArgumentList $sandbox_conf


By Strangely

Founding member of the band Crawling Chaos from the North-East of England

Leave a comment