99 lines
3.8 KiB
PowerShell
99 lines
3.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Instala el arranque fiable de OmniRoute al iniciar sesion de Windows.
|
|
|
|
.DESCRIPTION
|
|
Sustituye el autostart fragil de OmniRoute (un .vbs en la carpeta Inicio, ya
|
|
afectado por la deprecacion de VBScript en Windows) por una tarea programada
|
|
que ejecuta el vigilante omniroute_watchdog.ps1:
|
|
- Se lanza al iniciar sesion del usuario.
|
|
- Arranca OmniRoute si no esta corriendo.
|
|
- Lo relanza si se cae durante la sesion (autocuracion).
|
|
|
|
Pasos:
|
|
1. Desactiva el autostart propio de OmniRoute (OmniRoute.vbs) para evitar dobles arranques.
|
|
2. Registra la tarea programada "OmniRoute Watchdog".
|
|
3. La arranca ahora mismo.
|
|
|
|
.NOTES
|
|
No requiere privilegios de administrador (tarea del propio usuario).
|
|
#>
|
|
[CmdletBinding()]
|
|
param(
|
|
[switch]$NoStart
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
$TaskName = 'OmniRoute Watchdog'
|
|
$ScriptPath = Join-Path $PSScriptRoot 'omniroute_watchdog.ps1'
|
|
$PwshExe = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
|
|
$NodeExe = 'C:\Program Files\nodejs\node.exe'
|
|
$OmniRouteMjs = Join-Path $env:APPDATA 'npm\node_modules\omniroute\bin\omniroute.mjs'
|
|
$UserId = "$env:USERDOMAIN\$env:USERNAME"
|
|
|
|
Write-Host '== Instalando arranque fiable de OmniRoute ==' -ForegroundColor Cyan
|
|
|
|
# 1) Desactivar el autostart VBS propio de OmniRoute -----------------------
|
|
$vbs = Join-Path ([Environment]::GetFolderPath('Startup')) 'OmniRoute.vbs'
|
|
if ((Test-Path $NodeExe) -and (Test-Path $OmniRouteMjs)) {
|
|
Write-Host ' - Desactivando autostart VBS de OmniRoute...' -ForegroundColor Yellow
|
|
$prevEap = $ErrorActionPreference
|
|
$ErrorActionPreference = 'Continue'
|
|
try { & $NodeExe $OmniRouteMjs autostart disable 2>&1 | Out-Null } catch { }
|
|
$ErrorActionPreference = $prevEap
|
|
}
|
|
if (Test-Path $vbs) {
|
|
Remove-Item -LiteralPath $vbs -Force
|
|
Write-Host ' - Eliminado OmniRoute.vbs de la carpeta Inicio.' -ForegroundColor Yellow
|
|
}
|
|
|
|
# 2) Registrar la tarea programada -----------------------------------------
|
|
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
|
|
Write-Host ' - Eliminando tarea anterior...' -ForegroundColor Yellow
|
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
|
}
|
|
|
|
$Action = New-ScheduledTaskAction `
|
|
-Execute $PwshExe `
|
|
-Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$ScriptPath`"" `
|
|
-WorkingDirectory $env:USERPROFILE
|
|
|
|
$Trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
|
|
|
|
$Settings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-RestartCount 999 `
|
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
|
-MultipleInstances IgnoreNew
|
|
$Settings.ExecutionTimeLimit = 'PT0S' # sin limite de tiempo (vigilante permanente)
|
|
$Settings.Hidden = $true
|
|
|
|
$Principal = New-ScheduledTaskPrincipal -UserId $UserId -LogonType Interactive -RunLevel Limited
|
|
|
|
Register-ScheduledTask `
|
|
-TaskName $TaskName `
|
|
-Action $Action `
|
|
-Trigger $Trigger `
|
|
-Settings $Settings `
|
|
-Principal $Principal `
|
|
-Description 'Arranca y vigila OmniRoute (localhost:20128) al iniciar sesion. Autocuracion si se cae.' `
|
|
-Force | Out-Null
|
|
|
|
Write-Host " - Tarea '$TaskName' registrada." -ForegroundColor Green
|
|
|
|
# 3) Arrancar ahora ---------------------------------------------------------
|
|
if (-not $NoStart) {
|
|
Write-Host ' - Arrancando el vigilante ahora...' -ForegroundColor Yellow
|
|
Start-ScheduledTask -TaskName $TaskName
|
|
}
|
|
|
|
Write-Host ''
|
|
Write-Host 'Listo. Comandos utiles:' -ForegroundColor Cyan
|
|
Write-Host " Get-ScheduledTask -TaskName '$TaskName' | Get-ScheduledTaskInfo"
|
|
Write-Host " Start-ScheduledTask -TaskName '$TaskName'"
|
|
Write-Host " Stop-ScheduledTask -TaskName '$TaskName'"
|
|
Write-Host " Get-Content `"$env:USERPROFILE\.omniroute\watchdog.log`" -Tail 20"
|