Skip to content

Commit 0b44953

Browse files
v1.0.18
added tagging automation
1 parent 2786623 commit 0b44953

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
/.vs
66
/.vscode
7+
script.log

wht.ps1

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
#>
99

1010
# ==== Script version ====
11-
$scriptVersion = "1.0.17"
11+
$scriptVersion = "1.0.18"
1212

1313
# ==== Configuration ====
1414
$configFile = "$PSScriptRoot\adapter.config"
1515
$logFile = $true
1616
$logReverse = $false
1717
$logFilePath = "$PSScriptRoot\script.log"
18-
$restartWiFi = $false
18+
$restartWiFi = $true
1919
$forceAsAdmin = $true
20-
$delay = 30
20+
$delayViaScript = $true
21+
$delay = 90
2122

2223
# FORCE POWERSHELL 5.1 HANDOFF (Must come first to avoid Type errors in PS7)
2324
if ($PSVersionTable.PSVersion.Major -gt 5) {
@@ -159,6 +160,26 @@ try {
159160
return $false
160161
}
161162

163+
# Function to stop/start WireGuard tunnels to prevent registry bloat
164+
function Set-WireGuardTunnel {
165+
param ([string]$State) # "On" or "Off"
166+
167+
$wgPath = "C:\Program Files\WireGuard\wireguard.exe"
168+
if (-not (Test-Path $wgPath)) { return }
169+
170+
# Identify active tunnels
171+
# WireGuard often stores tunnel names in the registry or you can specify your tunnel name
172+
$tunnelName = "YourTunnelName" # Replace with your actual tunnel name
173+
174+
if ($State -eq "Off") {
175+
LogThis "Closing WireGuard tunnel to prevent stale connections..." -Color "Yellow"
176+
Start-Process -FilePath $wgPath -ArgumentList "/uninstalltunnelservice $tunnelName" -Wait -WindowStyle Hidden
177+
} else {
178+
LogThis "Re-activating WireGuard tunnel..." -Color "Cyan"
179+
Start-Process -FilePath $wgPath -ArgumentList "/installtunnelservice $tunnelName" -Wait -WindowStyle Hidden
180+
}
181+
}
182+
162183
# Main Hotspot Toggle Logic
163184
function Switch-Hotspot {
164185
param($adapter)
@@ -190,6 +211,9 @@ try {
190211
return $true
191212
}
192213

214+
# Pre-reset cleanup
215+
Set-WireGuardTunnel -State "Off"
216+
193217
LogThis "Resetting Radio for Win10 Routing Fix..." -Color "Cyan"
194218
Set-WifiRadioState -TargetState "Off"
195219
Start-Sleep -Seconds 2
@@ -222,14 +246,19 @@ if ($forceAsAdmin) { RunAsAdmin }
222246

223247
$targetAdapter = Get-WiFiAdapter
224248

225-
if (-not (IsRunningFromTerminal)) {
226-
LogThis "Background mode: Delaying $delay sec for system stability..."
249+
# You can delay here, or via Task Scheduler
250+
if ($delayViaScript -and -not (IsRunningFromTerminal)) {
251+
252+
LogThis "Background mode: Delaying $delay seconds."
227253
Start-Sleep -Seconds $delay
254+
228255
}
229256

257+
# Main Hotspot Toggle
230258
Switch-Hotspot -adapter $targetAdapter
231259
LogThis "==== Done ===="
232260

233261

234262

235263

264+

0 commit comments

Comments
 (0)