Last active
December 6, 2023 03:17
-
-
Save taschmidt/b2a86b9e5e1c41f05dd9fd4df7b3c5ce to your computer and use it in GitHub Desktop.
PIA set qBittorrent port forward
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# adapted from https://www.reddit.com/r/PrivateInternetAccess/comments/njwip9/qbittorrent_and_private_internet_access_pia_vpn/ | |
# requires running "Install-Module PsIni" | |
Import-Module PsIni | |
# get qBittorrent process | |
$qbProc = Get-Process qbittorrent -ErrorAction SilentlyContinue | |
# if qBit is running, it's closed | |
if ($qbProc) { | |
"qBittorrent is running. Stopping now..." | |
$null = Invoke-WebRequest -Uri http://localhost:8081/api/v2/app/shutdown -Method Post | |
"Waiting for qBittorrent to exit..." | |
$null = $qbProc.WaitForExit(60000) | |
$null = $qbProc.Refresh() | |
if (!$qbProc.HasExited) { | |
"qBittorrent didn't close. Terminating..." | |
Stop-Process -Id $qbProc.Id | |
$null = $qbProc.WaitForExit(15000) | |
$null = $qbProc.Refresh() | |
if (!$qbProc.HasExited) { | |
"ERROR: qBittorrent failed to close" | |
Exit 1 | |
} | |
} | |
} | |
# Check the forwarded port by PIA | |
$piaPort = & "${env:ProgramFiles}\Private Internet Access\piactl.exe" get portforward | |
"PIA port forward is $piaPort" | |
# Replace line in the .ini file | |
"Modifying qBittorrent settings..." | |
$qbIniPath = "${env:AppData}\qBittorrent\qBittorrent.ini" | |
$qbIni = Get-IniContent $qbIniPath | |
$qbIni["BitTorrent"]["Session\Port"] = $piaPort | |
$qbIni | Out-IniFile -FilePath $qbIniPath -Force | |
"Pausing..." | |
Start-Sleep -Seconds 5 | |
# start qBittorrent | |
"Starting qBittorrent..." | |
Start-Process -FilePath "${env:ProgramFiles}\qBittorrent\qbittorrent.exe" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment