No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

42 líneas
2.1KB

  1. $ErrorActionPreference = 'Stop'
  2. $root = Split-Path -Parent $PSScriptRoot
  3. $tempFolder = Join-Path $root 'temp'
  4. $null = New-Item -ItemType Directory -Path $tempFolder -Force
  5. $powerShellX86 = Join-Path $env:SystemRoot 'SysWOW64\WindowsPowerShell\v1.0\powershell.exe'
  6. $bridge = Join-Path $PSScriptRoot 'run-hidden-tool.ps1'
  7. $shell = New-Object -ComObject WScript.Shell
  8. foreach ($wait in @($true, $false)) {
  9. $token = [guid]::NewGuid().ToString('N')
  10. $requestPath = Join-Path $tempFolder ($token + '.request.json')
  11. $resultPath = Join-Path $tempFolder ($token + '.result.json')
  12. try {
  13. @{ ScriptName = 'dispatch-control.ps1'; ConfigPath = (Join-Path $root 'config.ini');
  14. Parameters = @{ Action = 'Status' } } |
  15. ConvertTo-Json -Compress -Depth 4 |
  16. Set-Content -LiteralPath $requestPath -Encoding UTF8
  17. $command = '"' + $powerShellX86 + '" -NoProfile -ExecutionPolicy Bypass -File "' +
  18. $bridge + '" -RequestPath "' + $requestPath + '" -ResultPath "' + $resultPath + '"'
  19. $exitCode = $shell.Run($command, 0, $wait)
  20. if (-not $wait) {
  21. for ($attempt = 0; $attempt -lt 160 -and
  22. -not (Test-Path -LiteralPath $resultPath -PathType Leaf); $attempt++) {
  23. Start-Sleep -Milliseconds 250
  24. }
  25. }
  26. if (-not (Test-Path -LiteralPath $resultPath -PathType Leaf)) {
  27. throw 'Hidden runner produced no result'
  28. }
  29. $response = Get-Content -LiteralPath $resultPath -Raw -Encoding UTF8 | ConvertFrom-Json
  30. if (($wait -and $exitCode -ne 0) -or -not $response.Success) {
  31. throw ('Hidden runner failed: ' + $response.Error)
  32. }
  33. $status = $response.Output | ConvertFrom-Json
  34. if ($null -eq $status.Paused) { throw 'Hidden runner status response is incomplete' }
  35. }
  36. finally {
  37. if (Test-Path -LiteralPath $requestPath) { Remove-Item -LiteralPath $requestPath -Force }
  38. if (Test-Path -LiteralPath $resultPath) { Remove-Item -LiteralPath $resultPath -Force }
  39. }
  40. }
  41. Write-Output 'Synchronous and asynchronous hidden helpers returned dispatch status'

Powered by TurnKey Linux.