-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_task_silent.ps1
More file actions
54 lines (42 loc) · 2.08 KB
/
setup_task_silent.ps1
File metadata and controls
54 lines (42 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Silent PowerShell Script for Installer - Setup Ethernet Toggle Auto-Startup
# This is called by the Inno Setup installer to configure auto-startup
param(
[Parameter(Mandatory=$true)]
[string]$InstallPath
)
$ErrorActionPreference = "Stop"
$TaskName = "NetworkKillSwitchApp"
try {
# Get the executable path
$exePath = Join-Path $InstallPath "NetworkKillSwitch.exe"
# Verify executable exists
if (-not (Test-Path $exePath)) {
Write-Error "Executable not found: $exePath"
exit 1
}
# Remove existing task if it exists (including old name)
$existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
if ($existingTask) {
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false | Out-Null
}
# Also remove old task name if it exists
$oldTask = Get-ScheduledTask -TaskName "EthernetToggleApp" -ErrorAction SilentlyContinue
if ($oldTask) {
Unregister-ScheduledTask -TaskName "EthernetToggleApp" -Confirm:$false | Out-Null
}
# Create scheduled task action
$action = New-ScheduledTaskAction -Execute $exePath -WorkingDirectory $InstallPath
# Create trigger for user logon
$trigger = New-ScheduledTaskTrigger -AtLogOn
# Create principal (run with highest privileges)
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive -RunLevel Highest
# Create settings
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Hours 0)
# Register the task
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Description "Auto-start Network Kill Switch system tray application" | Out-Null
exit 0
} catch {
# Silent failure - log to event log if possible
Write-EventLog -LogName Application -Source "Application" -EntryType Error -EventId 1000 -Message "Failed to setup Ethernet Toggle auto-start: $($_.Exception.Message)" -ErrorAction SilentlyContinue
exit 1
}