jcouturier
Posts: 27
Joined: Thu Jul 01, 2021 3:33 pm

custom action and environnement variable

Fri Jul 02, 2021 2:15 pm

Hello,
I would like to run an inline powershell script after the environment variables have been updated.
How should I do it please?
In Execution Time (powershell) I put After the system has been successfully modified
Thank you

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: custom action and environnement variable

Fri Jul 02, 2021 4:57 pm

Hello,

The environment variables are written during the following action: WriteEnvironmentStrings.

This action is part of the "Add resources" action group (from the "Custom Actions" page).

With that being said, in order to make sure you execute the PowerShell script after that, you could add the custom action as it follows:

- scheduled after the "Add resources" action group

- set its' "Execution Time" to "When the system is being modified (deferred)"

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

jcouturier
Posts: 27
Joined: Thu Jul 01, 2021 3:33 pm

Re: custom action and environnement variable

Fri Jul 02, 2021 6:16 pm

Hello,

Thank you for your answer.
It doesn't work.
Environnement variable is not recognized
when I run the installation with:

msiexec /i welcom.msi AI_DEBUGLOG=1 /L*V installLog.txt

I get the following log:

Param()

asadmin create-service domain1

# your code goes here
Write-Output "Le service Glassfish a été créé avec succès!"
ScriptPreambleparam(
[alias("propFile")] [Parameter(Mandatory=$true)] [string] $msiPropOutFilePath
,[alias("propSep")] [Parameter(Mandatory=$true)] [string] $msiPropKVSeparator
,[alias("scriptFile")] [Parameter(Mandatory=$true)] [string] $userScriptFilePath
,[alias("scriptArgsFile")][Parameter(Mandatory=$false)][string] $userScriptArgsFilePath
,[Parameter(Mandatory=$true)] [string] $testPrefix
,[switch] $isTest
)

Function AI_GetMsiProperty( [Parameter(Mandatory=$true)] [str
MSI (s) (F0:24) [19:08:59:302]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI23A0.tmp, Entrypoint: RunPowerShellScript
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:
ERROR: Le terme ®ÿasadminÿ¯ n'est pas reconnu comme nom d'applet de commande, fonction, fichier de script ou programme ex‚cutable. V‚rifiez l'orthographe du nom, ou si un chemin d'accŠs existe, v‚rifiez que le chemin d'accŠs est correct et r‚essayez.
CustomAction PowerShellScriptInline returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
L'action s'est terminée à 19:09:08: InstallExecute. Valeur de retour: 3
MSI (s) (F0:A0) [19:09:08:544]: Note: 1: 2265 2: 3: -2147287035
MSI (s) (F0:A0) [19:09:08:544]: User policy value 'DisableRollback' is 0

jcouturier
Posts: 27
Joined: Thu Jul 01, 2021 3:33 pm

Re: custom action and environnement variable

Tue Jul 06, 2021 1:12 pm

Hello,
I still have the problem. when i add powershell inline script, install fails.
I added a powershell script before mine to update the environment variable, it looks better but the installation always fails.
Here are the logs, can someone please help me?

Code: Select all

PublishFeatures: Fonctionnalité: Publication des Fonctionnalités du Produit
L'action s'est terminée à 14:02:17: PublishFeatures. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:146]: Doing action: PublishProduct
Action 14:02:17: PublishProduct. Publication des informations produit
Début de l'action: 14:02:17: PublishProduct.
1: Publication des informations produit 
L'action s'est terminée à 14:02:17: PublishProduct. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:146]: Doing action: AI_DATA_SETTER_3
Action 14:02:17: AI_DATA_SETTER_3. 
Début de l'action: 14:02:17: AI_DATA_SETTER_3.
MSI (s) (80:EC) [14:02:17:146]: PROPERTY CHANGE: Adding UpdateEnvironnementVariable property. Its value is 'DigitallySignScriptFlags2ParamsScript<#
.NOTES
  "pwsh.exe" is run if required version is greater or equal to 6, otherwise
  "powershell.exe" is invoked by default
#>

#Requires -version 3
Param()

# Your code goes here.
Add-Type -TypeDefinition @"

    using System;
    using System.Runtime.InteropServices;

    public class NativeMethods
    {
        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessageTimeout(
            IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
            uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
    }
"@

$HWND_BROADCAST = [IntPtr] 0xffff
$WM_SETTINGCHANGE = 0x1a
$SMTO_ABORTIFHUNG = 0x2
$result = [UIntPtr]::Zero

[void] ([Nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [UIntPtr]::Zero, 'Environment', $SMTO_ABORTIFHUNG, 5000, [ref] $result))ScriptPreambleparam(
  [alias("propFile")]      [Parameter(Mandat
L'action s'est terminée à 14:02:17: AI_DATA_SETTER_3. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:146]: Doing action: UpdateEnvironnementVariable
Action 14:02:17: UpdateEnvironnementVariable. 
Début de l'action: 14:02:17: UpdateEnvironnementVariable.
UpdateEnvironnementVariable: 
L'action s'est terminée à 14:02:17: UpdateEnvironnementVariable. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:146]: Doing action: AI_DATA_SETTER_2
Action 14:02:17: AI_DATA_SETTER_2. 
Début de l'action: 14:02:17: AI_DATA_SETTER_2.
MSI (s) (80:EC) [14:02:17:146]: PROPERTY CHANGE: Adding CreateGlassfishService property. Its value is 'DigitallySignScriptFlags2ParamsScript<#
.NOTES
  "pwsh.exe" is run if required version is greater or equal to 6, otherwise
  "powershell.exe" is invoked by default
#>

#Requires -version 3
Param()

asadmin create-service domain1

# your code goes here
Write-Output "Le service Glassfish a été créé avec succès!"
ScriptPreambleparam(
  [alias("propFile")]      [Parameter(Mandatory=$true)] [string] $msiPropOutFilePath
 ,[alias("propSep")]       [Parameter(Mandatory=$true)] [string] $msiPropKVSeparator
 ,[alias("scriptFile")]    [Parameter(Mandatory=$true)] [string] $userScriptFilePath
 ,[alias("scriptArgsFile")][Parameter(Mandatory=$false)][string] $userScriptArgsFilePath
 ,[Parameter(Mandatory=$true)]                          [string] $testPrefix
 ,[switch]                                                       $isTest
 )

Function AI_GetMsiProperty( [Parameter(Mandatory=$true)]  [string] $name
                          , [Parameter(Mandatory=$false)] $t
L'action s'est terminée à 14:02:17: AI_DATA_SETTER_2. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:146]: Doing action: CreateGlassfishService
Action 14:02:17: CreateGlassfishService. 
Début de l'action: 14:02:17: CreateGlassfishService.
CreateGlassfishService: 
L'action s'est terminée à 14:02:17: CreateGlassfishService. Valeur de retour: 1
MSI (s) (80:EC) [14:02:17:162]: Doing action: InstallExecute
Action 14:02:17: InstallExecute. 
Début de l'action: 14:02:17: InstallExecute.
MSI (s) (80:EC) [14:02:17:240]: Running Script: C:\Windows\Installer\MSI4617.tmp
MSI (s) (80:EC) [14:02:17:240]: PROPERTY CHANGE: Adding UpdateStarted property. Its value is '1'.
MSI (s) (80:EC) [14:02:17:334]: Note: 1: 2265 2:  3: -2147287035 
MSI (s) (80:EC) [14:02:17:334]: Machine policy value 'DisableRollback' is 0
MSI (s) (80:EC) [14:02:17:334]: Note: 1: 2318 2:  
MSI (s) (80:EC) [14:02:17:349]: Note: 1: 2318 2:  
MSI (s) (80:EC) [14:02:17:349]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2 
MSI (s) (80:EC) [14:02:17:349]: Executing op: Header(Signature=1397708873,Version=500,Timestamp=1390833736,LangId=1036,Platform=589824,ScriptType=1,ScriptMajorVersion=21,ScriptMinorVersion=4,ScriptAttributes=1)
MSI (s) (80:EC) [14:02:17:349]: Executing op: ProductInfo(ProductKey={D3019046-3176-4A5D-ACDF-D1829AC07D8E},ProductName=Welcom,PackageName=welcom.msi,Language=1036,Version=16777216,Assignment=1,ObsoleteArg=0,ProductIcon=favicon.exe,,PackageCode={3816D6B1-A6AB-4D3B-A8C7-FC8C42F89FEC},,,InstanceType=0,LUASetting=0,RemoteURTInstalls=0,ProductDeploymentFlags=3)
MSI (s) (80:EC) [14:02:17:349]: Executing op: DialogInfo(Type=0,Argument=1036)
MSI (s) (80:EC) [14:02:17:349]: Executing op: DialogInfo(Type=1,Argument=Welcom)

Catalin
Posts: 6542
Joined: Wed Jun 13, 2018 7:49 am

Re: custom action and environnement variable

Tue Jul 06, 2021 4:06 pm

Hello,

If you have updated the environment variables through a custom action, then most likely the problem is not related to them (i.e. env variables).

I can see the following in your PowerShell script:

Code: Select all

asadmin create-service domain1
I am not quite sure what this is, but I am not quite sure this is a correct syntax for PowerShell.

Does the code of your Custom Action work as expected outside of Advanced Installer? If the answer is no, then the problem relies in the code itself, not in something related to the installation process (in our case, setting the env variables).

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

Return to “Building Installers”