Option Explicit If WScript.Arguments.Count > 0 Then If LCase(WScript.Arguments(0)) = "syntax-only" Then WScript.Quit 0 End If End If Dim objShell Dim command Dim exitCode Set objShell = CreateObject("WScript.Shell") command = "$ErrorActionPreference='Stop';" & _ "$task=Get-ScheduledTask -TaskName 'VignettePublicRuntimeWatchdog' -ErrorAction Stop;" & _ "$action=@($task.Actions)[0];" & _ "if([IO.Path]::GetFileName($action.Execute) -ne 'wscript.exe'){throw 'Pinned watchdog task must execute wscript.exe'};" & _ "$root=$action.WorkingDirectory;if([string]::IsNullOrWhiteSpace($root)){throw 'Pinned watchdog working directory is missing'};" & _ "$quote=[char]34;$expectedScript=Join-Path $root 'scripts\watch-public-runtime.ps1';" & _ "$expectedLauncher=Join-Path $root 'scripts\watch-public-runtime-task.vbs';" & _ "if($action.Arguments.IndexOf($quote+$expectedLauncher+$quote,[StringComparison]::OrdinalIgnoreCase) -lt 0){throw 'Pinned watchdog launcher does not match its working directory'};" & _ "$expectedFileArg='-File '+$quote+$expectedScript+$quote;$expectedRootArg='-StableSourceRoot '+$quote+$root+$quote;" & _ "if($action.Arguments.IndexOf($expectedFileArg,[StringComparison]::OrdinalIgnoreCase) -lt 0){throw 'Pinned watchdog script path does not match its working directory'};" & _ "if($action.Arguments.IndexOf($expectedRootArg,[StringComparison]::OrdinalIgnoreCase) -lt 0){throw 'Pinned watchdog source root does not match its working directory'};" & _ "$required=@('-StableSourceRoot','-ExpectedSourceCommit','-ExpectedSourceTree','-ExpectedWatchdogSha256','-ExpectedStartScriptSha256');" & _ "foreach($marker in $required){if($action.Arguments.IndexOf($marker,[StringComparison]::Ordinal) -lt 0){throw ('Unpinned watchdog task action: missing '+$marker)}};" & _ "if($action.Arguments -match '(?i)(?:^|\s)-Workspace(?:\s|$)'){throw 'Legacy shared-worktree watchdog action is forbidden'};" & _ "Start-ScheduledTask -TaskName 'VignettePublicRuntimeWatchdog'" command = "powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -Command """ & _ Replace(command, """", """""") & """" If WScript.Arguments.Count > 0 Then If LCase(WScript.Arguments(0)) = "print-command" Then WScript.Echo command WScript.Quit 0 End If End If exitCode = objShell.Run(command, 0, True) WScript.Quit exitCode