neelbhatt
Posts: 5
Joined: Wed Jun 05, 2019 4:03 pm

Default selection for InstallTypeDlg dialog for non admin

Hello All,

We are using per machine\per user installation and for that we have added InstallTypeDlg dialog which gives user option to select they want to install for current user or for all.

But when normal user opens the installer, it shows option for all user which does not make sense for normal user and also the issue is by default "All user" is selected for normal user.

Is there any way we can make default selection on the basis of if the user is admin or not?
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Default selection for InstallTypeDlg dialog for non admin

Hi and welcome to our forums.

Please take a look on the "Default for InstallTypeDlg in mixed per-machine/user set" thread which discusses the same scenario.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
neelbhatt
Posts: 5
Joined: Wed Jun 05, 2019 4:03 pm

Re: Default selection for InstallTypeDlg dialog for non admin

Thanks .

But I am still confused what should we do. At the end of the thready, it is mentioned the issue is fixed. Is the issue which we are talking about?
Catalin
Posts: 6607
Joined: Wed Jun 13, 2018 7:49 am

Re: Default selection for InstallTypeDlg dialog for non admin

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:
Neel Sample Project.aip
(22.21 KiB) Downloaded 186 times
Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
neelbhatt
Posts: 5
Joined: Wed Jun 05, 2019 4:03 pm

Re: Default selection for InstallTypeDlg dialog for non admin

Wow, very nice explanation. I will surely give a try and really thankful to you guys :)
Catalin
Posts: 6607
Joined: Wed Jun 13, 2018 7:49 am

Re: Default selection for InstallTypeDlg dialog for non admin

You are always welcome, Neel.

Always glad to help.
:D

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
neelbhatt
Posts: 5
Joined: Wed Jun 05, 2019 4:03 pm

Re: Default selection for InstallTypeDlg dialog for non admin

Hello Guys,

Above things works well thanks but have one issue.

I can not see below steps in my advanced installer:

- go to "Dialogs" page

- select the "InstallTypeDlg" dialog

- delete the default "init Event"


We have valid license, we do not have enterprise license, so is it available only with enterprise?
Catalin
Posts: 6607
Joined: Wed Jun 13, 2018 7:49 am

Re: Default selection for InstallTypeDlg dialog for non admin

Hello Neel,

Indeed, this workaround requires the use of our "Dialog Editor" feature which is available starting with the Enterprise license type or above.

I am afraid I am not aware of any other way of achieving that beside using the "Dialog Editor" feature.
:(

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
neelbhatt
Posts: 5
Joined: Wed Jun 05, 2019 4:03 pm

Re: Default selection for InstallTypeDlg dialog for non admin

Okay thanks a lot for the update :)

One more question, is it possible to not show Everybody(all user) at all if the user is normal user and not admin?

With enterprise license it is fine as we would be buying that soon.
Catalin
Posts: 6607
Joined: Wed Jun 13, 2018 7:49 am

Re: Default selection for InstallTypeDlg dialog for non admin

Hello Neel,

You are always welcome.

I am afraid that is not possible with the earlier discussed approach, due to the fact that both radio buttons are included in a "Radio Button Group".

This may be achievable in other ways, but I am not sure if it is worth the effort and worth taking the risk of facing some errors in the future (since the "InstallTypeDlg" is a predefined dialog and is most likely to work as intended than a custom dialog which you can create to replicate the behavior).

Hope this helps.

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

Return to “Common Problems”