agenshield 2026.8.3 → 2026.8.4-beta.23090337
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.ps1 +127 -2
- package/package.json +1 -1
package/bin/install.ps1
CHANGED
|
@@ -20,8 +20,10 @@
|
|
|
20
20
|
apps/service/src/modules/campaigns/templates/install-script-windows.template.ts
|
|
21
21
|
(the per-campaign served copy, with CloudUrl/Token/Org/Version baked into
|
|
22
22
|
the source text - there is no shared build step across the two repos, so
|
|
23
|
-
a change to manifest resolution, ACL hardening, the checksum gate,
|
|
24
|
-
PSEdition-branched atomic file create below
|
|
23
|
+
a change to manifest resolution, ACL hardening, the checksum gate, the
|
|
24
|
+
PSEdition-branched atomic file create below, or the post-install
|
|
25
|
+
Start-AgenShieldTray launch (function + its non-elevated-parent call site +
|
|
26
|
+
the already-elevated narration line) must be re-applied there BY
|
|
25
27
|
HAND, and vice versa). This asymmetry is exactly how the two sides
|
|
26
28
|
independently carried the SAME broken 7-argument FileStream constructor
|
|
27
29
|
under .NET Core / PowerShell 7 for a time - update the OTHER side's Mirror
|
|
@@ -656,6 +658,109 @@ function Stop-AgenShieldTray {
|
|
|
656
658
|
Start-Sleep -Seconds 1
|
|
657
659
|
}
|
|
658
660
|
|
|
661
|
+
# Called ONLY from the still-NON-ELEVATED parent, after the elevated child has
|
|
662
|
+
# returned successfully (see the elevation gate below). The tray is a per-user
|
|
663
|
+
# app: starting it from the elevated body would run it as administrator, and
|
|
664
|
+
# under a UAC-elevated token it lands in the wrong session - so the one process
|
|
665
|
+
# in this flow that is already running as the console user is the one that
|
|
666
|
+
# launches it. Without this, Stop-AgenShieldTray kills the tray for an upgrade
|
|
667
|
+
# and nothing restarts it: the MSI registers the tray only as a per-user STARTUP
|
|
668
|
+
# item, so it reappears at the next sign-in while the closing line of this
|
|
669
|
+
# script tells the user to sign in from a tray that is not running.
|
|
670
|
+
#
|
|
671
|
+
# Every failure mode is a WARNING, never an error: the tray is presentation, the
|
|
672
|
+
# install is not blocked by it (the same posture Set-PendingEnrollmentIfRequested
|
|
673
|
+
# already has), and it always starts on its own at the next sign-in. Writes only
|
|
674
|
+
# to the host/warning streams and swallows Start-Process's own output so this can
|
|
675
|
+
# never contribute a value to the caller's exit code.
|
|
676
|
+
#
|
|
677
|
+
# The install root is resolved from $env:ProgramW6432, NOT $env:ProgramFiles.
|
|
678
|
+
# $env:ProgramFiles is WOW64-REDIRECTED: in a 32-bit PowerShell on 64-bit
|
|
679
|
+
# Windows it is 'C:\Program Files (x86)', while the x64 MSI installs the tray
|
|
680
|
+
# under the NATIVE 'C:\Program Files'. The Test-Path below would then fail and
|
|
681
|
+
# this function would report the tray as MISSING when it merely looked in the
|
|
682
|
+
# wrong tree - a "clean skip" that reads as intentional while silently
|
|
683
|
+
# defeating the launch this function exists to perform. $env:ProgramW6432 is
|
|
684
|
+
# always the native root: set in BOTH 32- and 64-bit processes on 64-bit
|
|
685
|
+
# Windows, absent only on 32-bit-only Windows, so it is checked FIRST with the
|
|
686
|
+
# plain variable as the fallback - the same W6432-first shape the architecture
|
|
687
|
+
# check in Main already uses for $env:PROCESSOR_ARCHITEW6432. This is the third
|
|
688
|
+
# instance of that bug class in the Windows work and the first with a test
|
|
689
|
+
# behind it; check-install-ps1.mjs now fails on any path built from a
|
|
690
|
+
# WOW64-redirected root.
|
|
691
|
+
#
|
|
692
|
+
# The leaf is 'AgenShield\tray\AgenShield.exe', NOT 'AgenShield\AgenShield.exe'.
|
|
693
|
+
# The MSI harvests the Electron app into a `tray` SUBDIRECTORY
|
|
694
|
+
# (`<ComponentGroup Id="Tray" Directory="TrayDir">`, TrayDir Name="tray"), and
|
|
695
|
+
# both of the MSI's own launch points agree: the HKCU Run value and the Start
|
|
696
|
+
# Menu shortcut each target `[INSTALLFOLDER]tray\AgenShield.exe`. Omitting
|
|
697
|
+
# `tray` made Test-Path fail on EVERY install, so this function reported the
|
|
698
|
+
# tray MISSING on the exact path it was added to launch - the shipped symptom.
|
|
699
|
+
# agenshield.wxs is the authority and this is pinned against it by
|
|
700
|
+
# check-install-ps1.mjs, because no runtime test can see the real layout: a
|
|
701
|
+
# spec that creates its own fixture at whatever path the code reads passes for
|
|
702
|
+
# both the right answer and the wrong one.
|
|
703
|
+
#
|
|
704
|
+
# The root is joined ONE COMPONENT PER Join-Path CALL on purpose:
|
|
705
|
+
# `Join-Path a b c` needs -AdditionalChildPath, which is PowerShell 6+ only, and
|
|
706
|
+
# a single 'AgenShield\tray\AgenShield.exe' leaf is not separator-correct on
|
|
707
|
+
# the non-Windows runtime the mirrored template's specs execute under.
|
|
708
|
+
function Start-AgenShieldTray {
|
|
709
|
+
try {
|
|
710
|
+
if (-not [Environment]::UserInteractive) {
|
|
711
|
+
Write-Info 'No interactive session (headless/MDM install) - not starting the AgenShield tray; it starts at the next sign-in.'
|
|
712
|
+
return
|
|
713
|
+
}
|
|
714
|
+
$programFilesNative = if ($env:ProgramW6432) { $env:ProgramW6432 } else { $env:ProgramFiles }
|
|
715
|
+
if (-not $programFilesNative) {
|
|
716
|
+
Write-Info 'The Program Files directory could not be resolved - not starting the AgenShield tray; it starts at the next sign-in.'
|
|
717
|
+
return
|
|
718
|
+
}
|
|
719
|
+
$trayPath = Join-Path (Join-Path (Join-Path $programFilesNative 'AgenShield') 'tray') 'AgenShield.exe'
|
|
720
|
+
if (-not (Test-Path -LiteralPath $trayPath)) {
|
|
721
|
+
Write-Info 'The AgenShield tray was not found in the install directory - it starts at the next sign-in.'
|
|
722
|
+
return
|
|
723
|
+
}
|
|
724
|
+
# Matched on EXECUTABLE PATH, not process name: Get-Process names are the
|
|
725
|
+
# basename without extension, compared case-insensitively, so the CLI at
|
|
726
|
+
# bin\agenshield.exe answers to 'AgenShield' too. A name-only test reports
|
|
727
|
+
# "already running" for a CLI the user happens to have open and skips the
|
|
728
|
+
# launch - the same silent non-start this function exists to fix, arriving
|
|
729
|
+
# after Stop-AgenShieldTray has already killed the real tray.
|
|
730
|
+
#
|
|
731
|
+
# Read through Win32_Process rather than a process object's .Path, which is
|
|
732
|
+
# backed by MainModule: a 32-bit PowerShell CANNOT enumerate a 64-bit
|
|
733
|
+
# process's modules, so on the WOW64 path .Path fails for the very tray
|
|
734
|
+
# being looked for and a second instance is started. This is the same
|
|
735
|
+
# redirection class as the install root above, one API layer down, and the
|
|
736
|
+
# WOW64 rule in check-install-ps1.mjs cannot see it - that rule covers
|
|
737
|
+
# environment reads. WMI's ExecutablePath needs no module handle, and is
|
|
738
|
+
# empty rather than fatal when it cannot be read.
|
|
739
|
+
#
|
|
740
|
+
# SessionId scopes the test to THIS logon: the tray is a per-user app, so
|
|
741
|
+
# another session's tray at the same path must not suppress this launch.
|
|
742
|
+
# BOUNDED, and SilentlyContinue rather than Stop. This runs in the parent
|
|
743
|
+
# immediately before `exit $exitCode`, so a wedged Winmgmt service or a
|
|
744
|
+
# broken WMI repository would block the one-liner from ever returning - an
|
|
745
|
+
# MDM/SCCM caller then reports a FAILED install that actually succeeded.
|
|
746
|
+
# -OperationTimeoutSec caps that (PowerShell 3.0+, so 5.1-safe); a healthy
|
|
747
|
+
# local query answers in milliseconds. On timeout or any CIM error the
|
|
748
|
+
# result is empty and the tray is LAUNCHED: for this function "cannot tell"
|
|
749
|
+
# must degrade to a possible duplicate tray, never to no tray, which is the
|
|
750
|
+
# very failure it was added to fix. -ErrorAction Stop would invert that.
|
|
751
|
+
$currentSessionId = (Get-Process -Id $PID).SessionId
|
|
752
|
+
$trayRunning = @(Get-CimInstance Win32_Process -Filter "Name = 'AgenShield.exe'" -OperationTimeoutSec 5 -ErrorAction SilentlyContinue | Where-Object { $_.ExecutablePath -eq $trayPath -and $_.SessionId -eq $currentSessionId })
|
|
753
|
+
if ($trayRunning.Count -gt 0) {
|
|
754
|
+
Write-Ok 'The AgenShield tray is already running.'
|
|
755
|
+
return
|
|
756
|
+
}
|
|
757
|
+
Start-Process -FilePath $trayPath | Out-Null
|
|
758
|
+
Write-Ok 'Started the AgenShield tray.'
|
|
759
|
+
} catch {
|
|
760
|
+
Write-WarnLine "Could not start the AgenShield tray - it starts at the next sign-in: $($_.Exception.Message)"
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
659
764
|
function Uninstall-AgenShield {
|
|
660
765
|
$code = Get-InstalledProductCode
|
|
661
766
|
if (-not $code) { return }
|
|
@@ -794,6 +899,17 @@ if (-not (Test-IsAdministrator)) {
|
|
|
794
899
|
if (Test-Path -LiteralPath $script:TranscriptPath) {
|
|
795
900
|
Get-Content -LiteralPath $script:TranscriptPath | ForEach-Object { Write-Host " | $_" }
|
|
796
901
|
}
|
|
902
|
+
|
|
903
|
+
# This process is the console user's own (non-elevated) shell, so it is the
|
|
904
|
+
# only place the per-user tray can be started with the right token - and only
|
|
905
|
+
# once the elevated child reports a clean install. Placed AFTER the transcript
|
|
906
|
+
# tail so the tray line lands under the child's own "AgenShield installed."
|
|
907
|
+
# output rather than ahead of it. $exitCode is read, never written, from here
|
|
908
|
+
# on: the one-liner's trailing "; exit $LASTEXITCODE" must keep reporting the
|
|
909
|
+
# INSTALL result, not the tray launch, and | Out-Null keeps Start-Process's
|
|
910
|
+
# own object off the stream this branch exits with.
|
|
911
|
+
if ($exitCode -eq 0) { Start-AgenShieldTray | Out-Null }
|
|
912
|
+
|
|
797
913
|
exit $exitCode
|
|
798
914
|
}
|
|
799
915
|
|
|
@@ -1027,6 +1143,15 @@ try {
|
|
|
1027
1143
|
Write-Host 'AgenShield installed.' -ForegroundColor Green
|
|
1028
1144
|
Write-Host ' Dashboard: http://localhost:5200'
|
|
1029
1145
|
Write-Host ' Sign in any time from the AgenShield tray to link your account.'
|
|
1146
|
+
# When this body ran under -ElevatedChild, the non-elevated PARENT starts the
|
|
1147
|
+
# tray as soon as this child exits 0. When it ran because the caller's own
|
|
1148
|
+
# shell was already Administrator there IS no non-elevated parent, and
|
|
1149
|
+
# starting a per-user app from an elevated shell would run it as administrator
|
|
1150
|
+
# in the wrong session - so say what happens instead of silently doing
|
|
1151
|
+
# nothing. Printed only when -not $ElevatedChild, so the child never says it.
|
|
1152
|
+
if (-not $ElevatedChild) {
|
|
1153
|
+
Write-Host ' This shell is already elevated, so the tray was not started from it (it must run as the signed-in user). Launch AgenShield from the Start menu, or sign out and back in.'
|
|
1154
|
+
}
|
|
1030
1155
|
Write-Host ''
|
|
1031
1156
|
} catch {
|
|
1032
1157
|
Write-ErrorLine $_.Exception.Message
|