v1.3.1: Add Install-ScheduledTask.ps1 for service deployment
- Creates scheduled task that runs as SYSTEM at boot - Runs with highest privileges, no user login required - Auto-restarts on failure (3 attempts, 1 min interval) - Runs hidden (no console window) - Supports -Uninstall to remove task 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
119
Install-ScheduledTask.ps1
Normal file
119
Install-ScheduledTask.ps1
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#Requires -RunAsAdministrator
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Installs eDNC Special Character Fix as a scheduled task that runs at startup with admin rights.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Creates a Windows scheduled task that:
|
||||||
|
- Runs at system startup
|
||||||
|
- Runs with highest privileges (Administrator)
|
||||||
|
- Runs whether user is logged on or not
|
||||||
|
- Automatically restarts if it stops
|
||||||
|
|
||||||
|
.PARAMETER WatchFolder
|
||||||
|
The folder to monitor. Default: C:\Dnc_Files\Q
|
||||||
|
|
||||||
|
.PARAMETER FileFilter
|
||||||
|
File pattern to watch. Default: *.pun
|
||||||
|
|
||||||
|
.PARAMETER Uninstall
|
||||||
|
Remove the scheduled task instead of installing.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\Install-ScheduledTask.ps1
|
||||||
|
Installs with default settings
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\Install-ScheduledTask.ps1 -WatchFolder "D:\DNC\Programs" -FileFilter "*.nc"
|
||||||
|
Installs with custom folder and filter
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
.\Install-ScheduledTask.ps1 -Uninstall
|
||||||
|
Removes the scheduled task
|
||||||
|
#>
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$WatchFolder = "C:\Dnc_Files\Q",
|
||||||
|
[string]$FileFilter = "*.pun",
|
||||||
|
[switch]$Uninstall
|
||||||
|
)
|
||||||
|
|
||||||
|
$TaskName = "eDNC Special Character Fix"
|
||||||
|
$ScriptPath = Join-Path $PSScriptRoot "eDNC-SpecialCharFix.ps1"
|
||||||
|
|
||||||
|
if ($Uninstall) {
|
||||||
|
Write-Host "Removing scheduled task '$TaskName'..." -ForegroundColor Yellow
|
||||||
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
|
Write-Host "Task removed." -ForegroundColor Green
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Verify script exists
|
||||||
|
if (-not (Test-Path $ScriptPath)) {
|
||||||
|
Write-Host "[ERROR] Script not found: $ScriptPath" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Installing eDNC Special Character Fix as Scheduled Task" -ForegroundColor Cyan
|
||||||
|
Write-Host "========================================================" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host " Task Name: $TaskName"
|
||||||
|
Write-Host " Script: $ScriptPath"
|
||||||
|
Write-Host " Watch Folder: $WatchFolder"
|
||||||
|
Write-Host " File Filter: $FileFilter"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# Remove existing task if present
|
||||||
|
$existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
||||||
|
if ($existingTask) {
|
||||||
|
Write-Host "Removing existing task..." -ForegroundColor Yellow
|
||||||
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build the PowerShell command
|
||||||
|
$Arguments = "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$ScriptPath`" -WatchFolder `"$WatchFolder`" -FileFilter `"$FileFilter`""
|
||||||
|
|
||||||
|
# Create the scheduled task
|
||||||
|
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $Arguments -WorkingDirectory $PSScriptRoot
|
||||||
|
|
||||||
|
# Trigger: At startup
|
||||||
|
$Trigger = New-ScheduledTaskTrigger -AtStartup
|
||||||
|
|
||||||
|
# Settings
|
||||||
|
$Settings = New-ScheduledTaskSettingsSet `
|
||||||
|
-AllowStartIfOnBatteries `
|
||||||
|
-DontStopIfGoingOnBatteries `
|
||||||
|
-StartWhenAvailable `
|
||||||
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
||||||
|
-RestartCount 3 `
|
||||||
|
-ExecutionTimeLimit (New-TimeSpan -Days 9999)
|
||||||
|
|
||||||
|
# Principal: Run as SYSTEM with highest privileges
|
||||||
|
$Principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
|
||||||
|
|
||||||
|
# Register the task
|
||||||
|
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal -Description "Monitors DNC folder and removes invalid special characters (0xFF) from program files."
|
||||||
|
|
||||||
|
Register-ScheduledTask -TaskName $TaskName -InputObject $Task | Out-Null
|
||||||
|
|
||||||
|
Write-Host "Scheduled task created successfully!" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "The task will start automatically at system boot." -ForegroundColor White
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "To start it now, run:" -ForegroundColor Yellow
|
||||||
|
Write-Host " Start-ScheduledTask -TaskName '$TaskName'"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "To check status:" -ForegroundColor Yellow
|
||||||
|
Write-Host " Get-ScheduledTask -TaskName '$TaskName' | Select-Object State"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "To uninstall:" -ForegroundColor Yellow
|
||||||
|
Write-Host " .\Install-ScheduledTask.ps1 -Uninstall"
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# Offer to start now
|
||||||
|
$response = Read-Host "Start the task now? (Y/N)"
|
||||||
|
if ($response -eq 'Y' -or $response -eq 'y') {
|
||||||
|
Start-ScheduledTask -TaskName $TaskName
|
||||||
|
Write-Host "Task started." -ForegroundColor Green
|
||||||
|
}
|
||||||
26
README.md
26
README.md
@@ -25,9 +25,30 @@ This utility monitors a folder for DNC files and automatically strips specified
|
|||||||
|
|
||||||
**Note:** The batch file automatically requests Administrator privileges via UAC prompt.
|
**Note:** The batch file automatically requests Administrator privileges via UAC prompt.
|
||||||
|
|
||||||
### Run at Startup (Optional)
|
### Run as Scheduled Task (Recommended)
|
||||||
|
|
||||||
To run automatically at Windows startup:
|
For production use, install as a scheduled task that runs as SYSTEM with admin rights:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Run as Administrator
|
||||||
|
.\Install-ScheduledTask.ps1
|
||||||
|
|
||||||
|
# With custom settings
|
||||||
|
.\Install-ScheduledTask.ps1 -WatchFolder "D:\DNC\Programs" -FileFilter "*.nc"
|
||||||
|
|
||||||
|
# To remove
|
||||||
|
.\Install-ScheduledTask.ps1 -Uninstall
|
||||||
|
```
|
||||||
|
|
||||||
|
This creates a task that:
|
||||||
|
- Starts at system boot (before any user logs in)
|
||||||
|
- Runs as SYSTEM with highest privileges
|
||||||
|
- Auto-restarts if it crashes
|
||||||
|
- Runs hidden (no console window)
|
||||||
|
|
||||||
|
### Run at User Login (Alternative)
|
||||||
|
|
||||||
|
To run when a specific user logs in:
|
||||||
|
|
||||||
1. Press `Win + R`, type `shell:startup`, press Enter
|
1. Press `Win + R`, type `shell:startup`, press Enter
|
||||||
2. Create a shortcut to `Run-eDNCFix.bat` in the Startup folder
|
2. Create a shortcut to `Run-eDNCFix.bat` in the Startup folder
|
||||||
@@ -131,6 +152,7 @@ The script uses exponential backoff (500ms → 1s → 2s → 4s → up to 16s) f
|
|||||||
|
|
||||||
| Version | Date | Changes |
|
| Version | Date | Changes |
|
||||||
|---------|------|---------|
|
|---------|------|---------|
|
||||||
|
| 1.3.1 | 2025-12-12 | Added Install-ScheduledTask.ps1 for running as SYSTEM service |
|
||||||
| 1.3.0 | 2025-12-12 | Fixed header UI, live status/stats, auto-elevate to Administrator |
|
| 1.3.0 | 2025-12-12 | Fixed header UI, live status/stats, auto-elevate to Administrator |
|
||||||
| 1.2.1 | 2025-12-12 | Added GE Aerospace ASCII banner |
|
| 1.2.1 | 2025-12-12 | Added GE Aerospace ASCII banner |
|
||||||
| 1.2.0 | 2025-12-12 | Immediate processing: 50ms delay, aggressive retry (100ms+), 15 attempts |
|
| 1.2.0 | 2025-12-12 | Immediate processing: 50ms delay, aggressive retry (100ms+), 15 attempts |
|
||||||
|
|||||||
Reference in New Issue
Block a user