Stabilize Windows logical host guard
CI / Rust checks (push) Canceled after 0s
CI / Docs and registry checks (push) Canceled after 0s
CI / Smoke checks (push) Canceled after 0s
Coverage / Coverage baseline (push) Canceled after 0s
Security / Cargo audit (push) Canceled after 0s
Security / Cargo deny (push) Canceled after 0s
Security / Secret pattern check (push) Canceled after 0s
Security / Dependency review (push) Canceled after 0s

This commit is contained in:
igor04091968
2026-07-01 06:06:42 +03:00
parent fe87c85a31
commit e658510442
14 changed files with 314 additions and 68 deletions
+23 -3
View File
@@ -1,6 +1,9 @@
[CmdletBinding()]
param(
[string]$UserId = 'SHARKON2025\user1'
[string]$ConfigPath = 'C:\ProgramData\AWatch-rus\deployment-config.json',
[string]$User = 'user1',
[string]$UserId,
[string]$AwHostname
)
Set-StrictMode -Version Latest
@@ -13,13 +16,30 @@ Start-Sleep -Seconds 10
Get-Process notepad -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
'@ | Set-Content -LiteralPath $probeScriptPath -Encoding UTF8
schtasks /Run /TN 'ActivityWatch Launch [SHARKON2025_user1]' | Out-Null
$config = $null
if (Test-Path -LiteralPath $ConfigPath) {
$config = Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json
}
$logicalHost = if (-not [string]::IsNullOrWhiteSpace($AwHostname)) {
$AwHostname
}
elseif ($config -and $config.PSObject.Properties.Name -contains 'awHostname' -and -not [string]::IsNullOrWhiteSpace([string]$config.awHostname)) {
[string]$config.awHostname
}
else {
[string]$env:COMPUTERNAME
}
$accountDomain = if (-not [string]::IsNullOrWhiteSpace($env:USERDOMAIN)) { [string]$env:USERDOMAIN } else { [string]$env:COMPUTERNAME }
$effectiveUserId = if (-not [string]::IsNullOrWhiteSpace($UserId)) { $UserId } else { '{0}\{1}' -f $accountDomain, $User }
$launchTaskName = 'ActivityWatch Launch [{0}_{1}]' -f $logicalHost, $User
schtasks /Run /TN $launchTaskName | Out-Null
Start-Sleep -Seconds 3
$taskName = 'AW User1 Notepad Probe'
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue
$action = New-ScheduledTaskAction -Execute (Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe') -Argument "-NoProfile -ExecutionPolicy Bypass -File $probeScriptPath"
$principal = New-ScheduledTaskPrincipal -UserId $UserId -LogonType Interactive -RunLevel Highest
$principal = New-ScheduledTaskPrincipal -UserId $effectiveUserId -LogonType Interactive -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit (New-TimeSpan -Minutes 5)
Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Settings $settings | Out-Null
Start-ScheduledTask -TaskName $taskName