Hello Neel,
As my colleague Eusebiu said, we do not offer predefined support for this.
However, this can be achieved through a custom action that will help us set the
"AI_InstallPerUser" property which defines which value is chosen:
- if AI_InstallPerUser = 1 ==> per-user is by default used ("Only for me")
- if AI_InstallPerUser = 0 ==> per-machine is by default used ("Everybody (all users")
In order to determine if a process is run elevated, we can use a custom action. For instance, in this sample, I will be using a PowerShell script to determine if the process is run elevated or not. However, you are not limited to this and you can use any other language that you are more familiar with.
Here is a little script which does what I have said above, setting a variable to either
"True" (if the process is run as admin) or
"False" (if otherwise). Based on the result of this, we will then set a Windows Installer property which we will use to condition the
"SetProperty" custom action that will set the
"AI_InstallPerUser" property accordingly:
Code: Select all
# Block for declaring the script parameters.
Param()
# Your code goes here.
Add-Type -AssemblyName PresentationFramework
$runAsAdmin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent() `
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if($runAsAdmin -eq $true){
# Set the MY_PROP to "0". This property will furher be used in deciding to which value we set
# the "AI_InstallPerUser" property.
AI_SetMsiProperty MY_PROP 0
}
elseif($runAsAdmin -eq $false){
# Set the MY_PROP to "1". This property will furher be used in deciding to which value we set
# the "AI_InstallPerUser" property.
AI_SetMsiProperty MY_PROP 1
}
Now that we have created our script, it is time to implement it in Advanced Installer. To do so, you can proceed as it follows:
- go to
"Custom Actions" page
- add a
"PowerShellScriptInline" custom action with sequence by pressing the
"Add custom action with sequence" button which is placed to the right side of the custom action's name.
- copy paste the above code in your custom action.
- schedule it accordingly. The dialogs are displayed during the
"User Selection" action group => we should schedule it before that. With that being said, simply drag and drop the custom action before the
"User Selection" action group in
"Wizard Dialogs Stage".
Now that we have created the custom action, it's time to set the
"AI_InstallPerUser" property based on the custom action's result. To do so, please proceed as it follows:
- go to
"Dialogs" page
- select the
"InstallTypeDlg" dialog
- delete the default
"init Event"
- create the following two init events:
Event: Set Installer property value
Property: AI_InstallPerUser
Argument: 1
Condition: MY_PROP="1"
Event: Set Installer property value
Property: AI_InstallPerUser
Argument: 0
Condition: MY_PROP="0"
Build and save the project. Run the setup with both elevated privileges and without them and the selection should be done automatically.
Attached for your reference you can find a sample project which I have created:
Hope this helps.
Best regards,
Catalin