fix: PowerShell 7 正确创建缺失的中继任务 (#112)
This commit is contained in:
parent
c96b314a9d
commit
77d6671de3
@ -85,14 +85,7 @@ $argumentList = @(
|
|||||||
'-ConfigPath', (ConvertTo-TaskArgument $privateConfigPath)
|
'-ConfigPath', (ConvertTo-TaskArgument $privateConfigPath)
|
||||||
)
|
)
|
||||||
$taskArguments = $argumentList -join ' '
|
$taskArguments = $argumentList -join ' '
|
||||||
$currentUser = if ([string]::IsNullOrWhiteSpace($env:USERNAME)) {
|
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||||
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
# Task Scheduler can return ERROR_FILE_NOT_FOUND when a local SAM account
|
|
||||||
# is registered with a stale or unresolvable machine-qualified prefix.
|
|
||||||
$env:USERNAME
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($PSCmdlet.ShouldProcess($TaskName, 'register and start the read-only upstream tunnel task')) {
|
if ($PSCmdlet.ShouldProcess($TaskName, 'register and start the read-only upstream tunnel task')) {
|
||||||
$privateConfigDirectory = Split-Path -Parent $privateConfigPath
|
$privateConfigDirectory = Split-Path -Parent $privateConfigPath
|
||||||
@ -174,6 +167,11 @@ if ($PSCmdlet.ShouldProcess($TaskName, 'register and start the read-only upstrea
|
|||||||
catch [System.Runtime.InteropServices.COMException] {
|
catch [System.Runtime.InteropServices.COMException] {
|
||||||
$existingTask = $null
|
$existingTask = $null
|
||||||
}
|
}
|
||||||
|
catch [System.IO.FileNotFoundException] {
|
||||||
|
# PowerShell 7 can translate Task Scheduler's missing-task HRESULT
|
||||||
|
# to FileNotFoundException instead of COMException.
|
||||||
|
$existingTask = $null
|
||||||
|
}
|
||||||
|
|
||||||
if ($null -ne $existingTask -and $existingTask.State -eq 4) {
|
if ($null -ne $existingTask -and $existingTask.State -eq 4) {
|
||||||
$statePath = $privateConfigPath + '.pid'
|
$statePath = $privateConfigPath + '.pid'
|
||||||
|
|||||||
@ -80,13 +80,13 @@ class BusinessMirrorScheduleTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_tunnel_task_uses_the_local_sam_account_and_hidden_powershell(): void
|
public function test_tunnel_task_accepts_both_missing_task_exception_types(): void
|
||||||
{
|
{
|
||||||
$contents = file_get_contents(dirname(__DIR__, 3) . '/scripts/install-upstream-tunnel-task.ps1');
|
$contents = file_get_contents(dirname(__DIR__, 3) . '/scripts/install-upstream-tunnel-task.ps1');
|
||||||
|
|
||||||
$this->assertIsString($contents);
|
$this->assertIsString($contents);
|
||||||
$this->assertStringContainsString('$env:USERNAME', $contents);
|
$this->assertStringContainsString('catch [System.Runtime.InteropServices.COMException]', $contents);
|
||||||
$this->assertStringContainsString("'-WindowStyle', 'Hidden'", $contents);
|
$this->assertStringContainsString('catch [System.IO.FileNotFoundException]', $contents);
|
||||||
$this->assertStringContainsString('TASK_LOGON_INTERACTIVE_TOKEN', $contents);
|
$this->assertStringContainsString('$rootFolder.GetTask($TaskName)', $contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user