andrii_tk
Posts: 4
Joined: Tue Mar 19, 2024 2:52 pm

AI_SetMsiProperty isn't working in inline Powershell immediate action

Hello,

Client reported about unsuccessful installation of the product, and I modified inline Powershell script to debug what's wrong.
It turned out that AI_SetMsiProperty didn't set property 'LEGACY_PRODUCT_CODE_FOUND' during script execution though AI_SetMsiProperty had been definitely reached. This property is required to decide if 'UninstallPreviousVersions' custom action should be triggered.
The error occurs only on one of the client’s machines; I could not reproduce it myself.

AI version: 20.9.1

DetectLegacyVersions Powershell script:

Code: Select all

Param($old_products, $old_version_threshold)

try {
	Write-Host "Old products: '$old_products'"
	$old_products = $old_products -split ';' | Where-Object { -not [string]::IsNullOrEmpty($_) }
	if ($old_products.Count -eq 0) {
		AI_SetMsiProperty LEGACY_PRODUCT_CODE_FOUND "0"
		Write-Host "Old products not found"
		return
	}

	$oldVersionThreshold = [System.Version]::new($old_version_threshold)
	$uninstall32Key = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{*}"

	$appsInfo = Get-ItemProperty -Path $uninstall32Key `
		| Select-Object `
			@{Name = 'Name'; Expression = { $_.DisplayName } },
			@{Name = 'Version'; Expression = { $_.DisplayVersion } },
			@{Name = 'ProductCode'; Expression = { $_.PSChildName } }

	$searchedOldProducts = $appsInfo `
		| Where-Object -FilterScript { 
			$old_products -contains $_.ProductCode -and [System.Version]::new($_.Version) -lt $oldVersionThreshold 
		}

	if (@($searchedOldProducts).Count -eq 0) {
		AI_SetMsiProperty LEGACY_PRODUCT_CODE_FOUND "0"
		Write-Host "Legacy products not found"
	} else {
		AI_SetMsiProperty LEGACY_PRODUCT_CODE_FOUND "1"
		Write-Host "Detected legacy products"
		$searchedOldProducts | Format-Table
	}
} 
catch {
	$exceptionInfo = $_.Exception
	throw
}
finally {
	if ($null -eq $exceptionInfo) {
		$found = AI_GetMsiProperty LEGACY_PRODUCT_CODE_FOUND
		if ($found -ne "1" -and $found -ne "0") {
			throw "Property 'LEGACY_PRODUCT_CODE_FOUND' is not assigned"
		}
	}
}
Execution order:
Screenshot 2024-03-20 105951.png
Screenshot 2024-03-20 105951.png (16.04 KiB) Viewed 10497 times
Script parameters and other options:
Screenshot 2024-03-20 110307.png
Screenshot 2024-03-20 110307.png (31.49 KiB) Viewed 10497 times
Attached logs:
installerlog.log
(98.46 KiB) Downloaded 31 times
Error line: 520
MSI (c) (CC:3C) [08:20:17:293]: Doing action: DetectLegacyVersions
Action 08:20:17: DetectLegacyVersions.
Action start 08:20:17: DetectLegacyVersions.
MSI (c) (CC:4C) [08:20:17:297]: Invoking remote custom action. DLL: C:\Users\someuser\AppData\Local\Temp\MSI2AE.tmp, Entrypoint: RunPowerShellScript
[INFO] PowerShell script preferred invocation folder:
Dumping PowerShell invoke log ...
--> Found PowerShell path: C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
--> PowerShell Script Execution Result Code: 574
--> PowerShell Script Execution log:
Old products: ''
Old products not found
ERROR: Property 'LEGACY_PRODUCT_CODE_FOUND' is not assigned
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hello and welcome to our forums,

The fact that this only reproduces on one customer's machine means it will be quite hard to investigate, as most likely it's a corner case.

I honestly can not think of any reason why setting the property would fail.

Does your customer have any AV software installed? If so, can you perhaps check any logs there to see if any temporary files were blocked?

Another thing I can think of is trying to manually run the PowerShell script on the customer's machine. Of course, here we should remove the SetProperty cmdlets and replace them with some messageboxes or variables to make sure it executes correctly. I am thinking that perhaps the script misbehaves on the customer's machine.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
andrii_tk
Posts: 4
Joined: Tue Mar 19, 2024 2:52 pm

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hi Catalin,

Yes, customer has AV software, I do think it's Microsoft Defender. Do you want to see AV logs, did I understand you correctly?

Regarding running script on customer's machine separately, we can do it, but it's not needed. Client tried to run installation multiple times and there were the same results: script was executed and actually reached code which sets AI property, because powershell's cmdlet Write-Line notified about result in the logs "Old products not found".

Sincerely,
Andrii
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hello Andrii,
Do you want to see AV logs, did I understand you correctly?
No, not quite. I was just curious if the AV somehow complained about the script execution, but this doesn't really make sense as it would block the entire script not just one cmdlet.

Do you think it would be possible to replace your script and only let the following:

Code: Select all

AI_SetMsiProperty LEGACY_PRODUCT_CODE_FOUND "0"
return
and let me know how that goes (e.g. if the propert is correctly set)?

Additionally, could you please send me a copy of your AIP file by email at support at advancedinstaller dot com so I can further investigate its' settings?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
andrii_tk
Posts: 4
Joined: Tue Mar 19, 2024 2:52 pm

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Thanks for the quick response,
Do you think it would be possible to replace your script
Yes, I posted installer with updated script to customer, I will write results as soon as they're ready.
Additionally, could you please send me a copy of your AIP file by email at support at advancedinstaller dot com so I can further investigate its' settings?
Sure, I have just sent AIP file to the support email.

Sincerely,
Andrii
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hello Andrii,

Thanks for the sent files.

Let's continue the thread over the forum for now so we avoid duplicates.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
andrii_tk
Posts: 4
Joined: Tue Mar 19, 2024 2:52 pm

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hi Catalin,

The modified script didn't manage to execute AI_SetMsiProperty (same issue).
So it was decided to make property "LEGACY_PRODUCT_CODE_FOUND" 1 by default to prevent errors in case such an issue with property setting happens.

Topic can be closed. Thanks for your support.
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: AI_SetMsiProperty isn't working in inline Powershell immediate action

Hello Andrii,

Thank you for your followup on this and for sharing the solution with us. :)

I'm sure this will be of help for further users facing a similar scenario.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”