Skip to content

Instantly share code, notes, and snippets.

@TechnoSparks
Last active February 5, 2022 02:43
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 TechnoSparks/c92ba15373b221099ebc71aff3c0e38c to your computer and use it in GitHub Desktop.
Save TechnoSparks/c92ba15373b221099ebc71aff3c0e38c to your computer and use it in GitHub Desktop.

Pause Duplicati if Process exists

Requirements

  • Powershell 5+
  • Duplicati Client binary built and is in PATH
  • Both files need to be in a same dir

Note

  • pause duplicati onProcess.launcher.pid.txt is created and contains the script's PID so that if there's a need to stop the script, the user can do so via Task Manager

Install

  1. Create a shortcut to pause duplicati onProcess.launcher.vbs in shell:startup
  2. If you are using native Powershell 5, rename pwsh to powershell in pause duplicati onProcess.launcher.vbs
  3. Modify process array in pause duplicati onProcess.ps1
Set objShell = WScript.CreateObject("WScript.Shell")
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
strFolder = objFSO.GetParentFolderName(objFile)
Do While True
objShell.Run("pwsh -WindowStyle Hidden -File """ & strFolder & "\pause duplicati onProcess.ps1"""), 0, True
Loop
$title = "Pause Duplicati onProcess"
$filetitle = "pause duplicati onProcess"
$host.UI.RawUI.WindowTitle = $title
$PID | Out-File -FilePath "$PSScriptRoot\$filetitle.pid.txt"
function errorDialog {
param (
$errorText
)
Add-Type -AssemblyName PresentationCore,PresentationFramework
$ButtonType = [System.Windows.MessageBoxButton]::OK
$MessageboxTitle = "$title script"
$Messageboxbody = $errorText
$MessageIcon = [System.Windows.MessageBoxImage]::Warning
[System.Windows.MessageBox]::Show($Messageboxbody,$MessageboxTitle,$ButtonType,$messageicon)
}
$process = "r5apex","VALORANT-Win64-Shipping"
Write-Host "Logging into Duplicati"
duplicati_client.exe login
if($? -eq $false) {
errorDialog -errorText "Login failure"
Write-Host "Error occured!"
exit
}
while($true) {
$isGaming = $false
foreach($p in $process) {
Write-Host "Checking process name $p"
$processHandle = get-process -Name "$p" -ErrorAction SilentlyContinue
if($processHandle) {
Write-Host "Currently gaming! Process name: $($processHandle.Name)"
$isGaming = $true
$activeProcess = $processHandle
break
}
}
if($isGaming -eq $true) {
Write-Host "Pausing Duplicati"
duplicati_client.exe pause
Write-Host "Wait for game to exit"
wait-process -Id $activeProcess.Id
Write-Host "Game exited. Resuming Duplicati"
duplicati_client.exe resume
} else {
Write-Host "No games running. Checking again in 120 seconds"
Start-Sleep -Seconds 120
Clear-Host
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment