Make Raven Muninn task actions hidden launchers
This commit is contained in:
parent
33fb6515bd
commit
49978cbb92
4 changed files with 106 additions and 18 deletions
|
|
@ -17,6 +17,7 @@ $ErrorActionPreference = "Stop"
|
|||
|
||||
$remoteScript = @"
|
||||
`$ErrorActionPreference = "Stop"
|
||||
`$ProgressPreference = "SilentlyContinue"
|
||||
if (-not (Test-Path -LiteralPath "$MuninnExe")) {
|
||||
throw "Muninn executable not found at $MuninnExe"
|
||||
}
|
||||
|
|
@ -31,6 +32,7 @@ Get-CimInstance Win32_Process |
|
|||
`$muninnDir = Split-Path -Parent "$MuninnExe"
|
||||
`$launcher = Join-Path `$muninnDir "activate-raven-av-srt.cmd"
|
||||
`$psLauncher = Join-Path `$muninnDir "activate-raven-av-srt.ps1"
|
||||
`$vbsLauncher = Join-Path `$muninnDir "activate-raven-av-srt-hidden.vbs"
|
||||
`$pidPath = Join-Path "$LogRoot" "muninn-activate.pid"
|
||||
`$obsArgs = ""
|
||||
if (-not [bool]::Parse("$($NoObsTarget.IsPresent)") -and -not ("$TargetHost" -eq "$ObsTargetHost" -and $Port -eq $ObsPort)) {
|
||||
|
|
@ -48,22 +50,32 @@ if (`$obsArgs -like " --no-obs-target") {
|
|||
`$encodedArguments = (`$arguments | ConvertTo-Json -Compress)
|
||||
`$psLines = @(
|
||||
'`$ErrorActionPreference = "Stop"',
|
||||
'`$ProgressPreference = "SilentlyContinue"',
|
||||
'`$arguments = ''$encodedArguments'' | ConvertFrom-Json',
|
||||
'`$process = Start-Process -FilePath "$MuninnExe" -ArgumentList `$arguments -WindowStyle Hidden -PassThru -RedirectStandardOutput "$LogRoot\muninn-activate.out.log" -RedirectStandardError "$LogRoot\muninn-activate.err.log"',
|
||||
'`$process.Id | Set-Content -Encoding ASCII -LiteralPath "$LogRoot\muninn-activate.pid"'
|
||||
)
|
||||
Set-Content -LiteralPath `$psLauncher -Value `$psLines -Encoding ASCII
|
||||
`$vbsLines = @(
|
||||
'Set shell = CreateObject("WScript.Shell")',
|
||||
'psLauncher = "$psLauncher"',
|
||||
'shell.Run "powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File """ & psLauncher & """", 0, False'
|
||||
)
|
||||
Set-Content -LiteralPath `$vbsLauncher -Value `$vbsLines -Encoding ASCII
|
||||
`$lines = @(
|
||||
"@echo off",
|
||||
"cd /d ""`$muninnDir""",
|
||||
"powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""`$psLauncher"""
|
||||
"wscript.exe //B //Nologo ""`$vbsLauncher"""
|
||||
)
|
||||
Set-Content -LiteralPath `$launcher -Value `$lines -Encoding ASCII
|
||||
cmd /c "schtasks /Delete /TN GameCult-Muninn-Activate /F 2>NUL"
|
||||
cmd /c schtasks /Create /TN GameCult-Muninn-Activate /SC ONCE /ST 23:59 /TR `$launcher /RL HIGHEST /F
|
||||
cmd /c schtasks /Run /TN GameCult-Muninn-Activate
|
||||
`$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "//B //Nologo ""`$vbsLauncher"""
|
||||
`$taskTrigger = New-ScheduledTaskTrigger -Once -At ([DateTime]::Today.AddHours(23).AddMinutes(59))
|
||||
`$taskPrincipal = New-ScheduledTaskPrincipal -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) -LogonType Interactive -RunLevel Limited
|
||||
`$taskSettings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew
|
||||
Register-ScheduledTask -TaskName "GameCult-Muninn-Activate" -Action `$taskAction -Trigger `$taskTrigger -Principal `$taskPrincipal -Settings `$taskSettings -Force | Out-Null
|
||||
Start-ScheduledTask -TaskName "GameCult-Muninn-Activate"
|
||||
"@
|
||||
|
||||
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteScript))
|
||||
& ssh.exe -o BatchMode=yes -o ConnectTimeout=10 $RavenHost "powershell.exe -NoProfile -EncodedCommand $encoded"
|
||||
& ssh.exe -o BatchMode=yes -o ConnectTimeout=10 $RavenHost "powershell.exe -NoProfile -NonInteractive -EncodedCommand $encoded"
|
||||
exit $LASTEXITCODE
|
||||
|
|
|
|||
71
scripts/repair-raven-muninn-task-actions.ps1
Normal file
71
scripts/repair-raven-muninn-task-actions.ps1
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
param(
|
||||
[string] $RavenHost = "raven",
|
||||
[string] $MuninnDir = "C:\Meta\Odin\Muninn"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$remoteScript = @"
|
||||
`$ErrorActionPreference = "Stop"
|
||||
`$ProgressPreference = "SilentlyContinue"
|
||||
|
||||
function Register-HiddenVbsTask {
|
||||
param(
|
||||
[Parameter(Mandatory = `$true)] [string] `$TaskName,
|
||||
[Parameter(Mandatory = `$true)] [string] `$VbsPath
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath `$VbsPath)) {
|
||||
throw "Hidden launcher not found for `$TaskName at `$VbsPath"
|
||||
}
|
||||
|
||||
`$action = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "//B //Nologo ""`$VbsPath"""
|
||||
`$trigger = New-ScheduledTaskTrigger -Once -At ([DateTime]::Today.AddHours(23).AddMinutes(59))
|
||||
`$principal = New-ScheduledTaskPrincipal -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) -LogonType Interactive -RunLevel Limited
|
||||
`$settings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew
|
||||
Register-ScheduledTask -TaskName `$TaskName -Action `$action -Trigger `$trigger -Principal `$principal -Settings `$settings -Force | Out-Null
|
||||
}
|
||||
|
||||
`$serveVbs = Join-Path "$MuninnDir" "start-muninn-serve-hidden.vbs"
|
||||
`$activateCmd = Join-Path "$MuninnDir" "activate-raven-av-srt.cmd"
|
||||
`$activateVbs = Join-Path "$MuninnDir" "activate-raven-av-srt-hidden.vbs"
|
||||
`$videoProofCmd = Join-Path "$MuninnDir" "muninn-raven-video-to-starfire-obs.cmd"
|
||||
`$videoProofVbs = Join-Path "$MuninnDir" "muninn-raven-video-to-starfire-obs-hidden.vbs"
|
||||
|
||||
function Write-HiddenCmdLauncher {
|
||||
param(
|
||||
[Parameter(Mandatory = `$true)] [string] `$CmdPath,
|
||||
[Parameter(Mandatory = `$true)] [string] `$VbsPath
|
||||
)
|
||||
|
||||
if (-not (Test-Path -LiteralPath `$CmdPath)) {
|
||||
throw "Command launcher not found at `$CmdPath"
|
||||
}
|
||||
|
||||
`$lines = @(
|
||||
'Set shell = CreateObject("WScript.Shell")',
|
||||
"cmdPath = ""`$CmdPath""",
|
||||
'shell.Run """" & cmdPath & """", 0, False'
|
||||
)
|
||||
Set-Content -LiteralPath `$VbsPath -Value `$lines -Encoding ASCII
|
||||
}
|
||||
|
||||
if ((Test-Path -LiteralPath `$activateCmd) -and -not (Test-Path -LiteralPath `$activateVbs)) {
|
||||
Write-HiddenCmdLauncher -CmdPath `$activateCmd -VbsPath `$activateVbs
|
||||
}
|
||||
if ((Test-Path -LiteralPath `$videoProofCmd) -and -not (Test-Path -LiteralPath `$videoProofVbs)) {
|
||||
Write-HiddenCmdLauncher -CmdPath `$videoProofCmd -VbsPath `$videoProofVbs
|
||||
}
|
||||
|
||||
Register-HiddenVbsTask -TaskName "GameCult-Muninn" -VbsPath `$serveVbs
|
||||
if (Test-Path -LiteralPath `$activateVbs) {
|
||||
Register-HiddenVbsTask -TaskName "GameCult-Muninn-Activate" -VbsPath `$activateVbs
|
||||
}
|
||||
if (Test-Path -LiteralPath `$videoProofVbs) {
|
||||
Register-HiddenVbsTask -TaskName "GameCult-Muninn-VideoProof" -VbsPath `$videoProofVbs
|
||||
}
|
||||
"@
|
||||
|
||||
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteScript))
|
||||
& ssh.exe -o BatchMode=yes -o ConnectTimeout=10 $RavenHost "powershell.exe -NoProfile -NonInteractive -EncodedCommand $encoded"
|
||||
exit $LASTEXITCODE
|
||||
|
|
@ -46,9 +46,12 @@ Set-Content -LiteralPath `$vbsLauncher -Value `$vbsLines -Encoding ASCII
|
|||
"wscript.exe //B //Nologo ""`$vbsLauncher"""
|
||||
)
|
||||
Set-Content -LiteralPath `$launcher -Value `$lines -Encoding ASCII
|
||||
cmd /c "schtasks /Delete /TN GameCult-Muninn /F 2>NUL"
|
||||
cmd /c schtasks /Create /TN GameCult-Muninn /SC ONCE /ST 23:59 /TR `$launcher /RL LIMITED /F
|
||||
cmd /c schtasks /Run /TN GameCult-Muninn
|
||||
`$taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "//B //Nologo ""`$vbsLauncher"""
|
||||
`$taskTrigger = New-ScheduledTaskTrigger -Once -At ([DateTime]::Today.AddHours(23).AddMinutes(59))
|
||||
`$taskPrincipal = New-ScheduledTaskPrincipal -UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) -LogonType Interactive -RunLevel Limited
|
||||
`$taskSettings = New-ScheduledTaskSettingsSet -MultipleInstances IgnoreNew
|
||||
Register-ScheduledTask -TaskName "GameCult-Muninn" -Action `$taskAction -Trigger `$taskTrigger -Principal `$taskPrincipal -Settings `$taskSettings -Force | Out-Null
|
||||
Start-ScheduledTask -TaskName "GameCult-Muninn"
|
||||
"@
|
||||
|
||||
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteScript))
|
||||
|
|
|
|||
Loading…
Reference in a new issue