Overall Goal: The installer will first check if the operating system is Windows 10 LTSC. If it is, it will then use a PowerShell script to check if Windows Update KB5053606 is installed. If the update is not installed, the same PowerShell script will be invoked to attempt to trigger its installation via the Windows Update service. All operations and their outcomes will be logged to the InnoSetup log file. The main SoundSwitch installation will proceed regardless of the outcome of these update checks or installation attempts (silent failure with logging).
Detailed Plan:
-
Helper Script (PowerShell):
- Filename:
ManageWindowsUpdate.ps1 - Location: To be placed in
Installer/scripts/relative tosetup.iss. - Functionality:
- Accepts parameters:
-KBArticleID <string>(e.g., "KB5053606")-Action <string>(e.g., "CheckInstalled" or "TriggerInstall")
- If
Actionis "CheckInstalled":- Uses
Get-HotFix -Id $KBArticleIDor queries WMI (Get-WmiObject -Class Win32_QuickFixEngineering -Filter "HotFixID='$KBArticleID'") to check if the specified KB is installed. - Exits with code
0if found. - Exits with code
1if not found. - Exits with other codes for errors (e.g.,
2ifGet-HotFixfails or WMI query fails). - Logs its findings (e.g., using
Write-Outputfor InnoSetup to capture, or to a dedicated log if more detail is needed from the PS script).
- Uses
- If
Actionis "TriggerInstall":- Uses the Windows Update Agent API (e.g.,
Microsoft.Update.Session,Microsoft.Update.Searcher,IUpdateDownloader,IUpdateInstaller2) to search for the specific KB, download it if necessary, and initiate the installation. - Logs its progress and outcome.
- This action should be designed to run without blocking the InnoSetup installer for too long (e.g., by initiating the update and exiting).
- Uses the Windows Update Agent API (e.g.,
- Accepts parameters:
- Filename:
-
Inno Setup Script (
Installer/setup.iss) Modifications:-
[Files]Section:- Add an entry to include
ManageWindowsUpdate.ps1. It will be extracted to{tmp}during setup and deleted after installation.
[Files] ; ... existing files ... Source: "scripts\ManageWindowsUpdate.ps1"; DestDir: "{tmp}"; Flags: confirmoverwrite deleteafterinstall
- Add an entry to include
-
[Code]Section:- Constants:
const KBID_TO_CHECK = 'KB5053606'; LTSC_PRODUCT_NAME_1 = 'Windows 10 Enterprise LTSC'; LTSC_PRODUCT_NAME_2 = 'Windows 10 Enterprise LTSB'; // Older naming
- Logging Function:
procedure LogMsg(Msg: String); begin Log(FormatDateTime('yyyy-mm-dd hh:nn:ss', Now) + ': ' + Msg); end;
IsWin10LTSC(): Boolean;Function:- Reads
ProductNamefromHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion. - Checks if it contains
LTSC_PRODUCT_NAME_1orLTSC_PRODUCT_NAME_2. - Logs the detected OS and the result of the LTSC check.
- Returns
Trueif LTSC,Falseotherwise. Logs an error and returnsFalseif the registry key cannot be read.
- Reads
IsKBInstalledPS(KBID: String): Boolean;Function:- Locates
powershell.exe. - Constructs the command:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "{tmp}\ManageWindowsUpdate.ps1" -KBArticleID "<KBID>" -Action CheckInstalled. - Executes this command hidden using
Execand waits for it to terminate. - Checks the
ExitCode.0means installed (True).1means not installed (False). Any other code means an error occurred (treat asFalse, log the actual exit code). - Logs the command executed and the outcome.
- Locates
AttemptKBInstallPS(KBID: String);Procedure:- Locates
powershell.exe. - Constructs the command:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "{tmp}\ManageWindowsUpdate.ps1" -KBArticleID "<KBID>" -Action TriggerInstall. - Executes this command hidden using
Execwith theewNoWaitflag. - Logs the attempt to trigger the installation.
- Locates
InitializeSetup(): Boolean;Event Function:- This function is called when setup is initializing.
- Calls
LogMsg('Starting Windows Update prerequisite check.'). - Calls
IsWin10LTSC(). - If LTSC is detected:
- Calls
IsKBInstalledPS(KBID_TO_CHECK). - If the KB is not installed, calls
AttemptKBInstallPS(KBID_TO_CHECK).
- Calls
- Else (not LTSC):
- Calls
LogMsg('System is not Windows 10 LTSC. Skipping update check for ' + KBID_TO_CHECK + '.').
- Calls
- All results and error conditions encountered by these functions will be logged.
- Always returns
Trueto allow the SoundSwitch installation to proceed. - Calls
LogMsg('Windows Update prerequisite check finished. Proceeding with main installation.').
- Constants:
-
Ensure
SetupLogging=yesis present in the[Setup]section.
-
Mermaid Diagram of the Logic:
graph TD
A[Installer Starts] --> LogInit[Log: Begin Update Check];
LogInit --> B{Call IsWin10LTSC()};
B -- True --> LogLTSC[Log: LTSC Detected];
LogLTSC --> C{Call IsKBInstalledPS('KB5053606') via ManageWindowsUpdate.ps1 -Action CheckInstalled};
B -- False --> LogNotLTSC[Log: Not LTSC / Skip Update Check];
LogNotLTSC --> Z[Proceed with SoundSwitch Installation];
C -- Exit Code 0 (Installed) --> LogKBFound[Log: KB5053606 Installed];
LogKBFound --> Z;
C -- Exit Code 1 (Not Installed) --> LogKBNotFound[Log: KB5053606 Not Installed];
LogKBNotFound --> D[Call AttemptKBInstallPS('KB5053606') via ManageWindowsUpdate.ps1 -Action TriggerInstall];
D --> LogAttempt[Log: Attempted to Trigger KB Install];
LogAttempt --> Z;
C -- Other Exit Codes (Error) --> LogKBCheckError[Log: Error checking KB5053606 (Exit Code: <val>)];
LogKBCheckError --> Z;
B -- Error During LTSC Check --> LogLTSCError[Log: Error Checking LTSC];
LogLTSCError --> Z;
Z --> LogFinal[Log: Update Check Finished. Proceeding with Main Install.]