Deepak Singh
Posts: 13
Joined: Tue May 12, 2020 12:05 pm

Restrict users not to add spaces in the installation path

Hi,

There is a dialog named FolderDlg in AI projects which takes the path where the installation will be done. I just want to restrict users to not enter any space in the installation path. If there is any space then on click of the Next button on the FolderDlg the error message should pop up that the spaces in the installation path are not allowed. Is it possible? I have investigated in the AI community regarding this scenario but I didn't get any way around. Can you help me with this? 

Thanks and regards,
Deepak
Attachments
Issue For spaces in AI community.png
Issue For spaces in AI community.png (32.33 KiB) Viewed 5952 times
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Restrict users not to add spaces in the installation path

Hello Deepak,

Yes, it is possible to achieve that.

For instance, we can use a script that will check if the APPDIR contains any spaces and, if so, set a property accordingly. Based on this property, we can decide whether we let the user proceed or not.

For instance, a PowerShell script that does that looks like this:

Code: Select all

# Block for declaring the script parameters.
Param()

# Your code goes here.

Add-Type -AssemblyName PresentationFramework

$appdir = AI_GetMsiProperty APPDIR

if ($appdir -match " "){

[System.Windows.MessageBox]::Show("Please remove the spaces from the installation path!")

AI_SetMsiProperty CONTAINS_SPACES true

}

else{

AI_SetMsiProperty CONTAINS_SPACES false

}
You can add this in your project as a "PowerShellScriptInline" custom action, without sequence (so we can execute it from a dialog control).

You can then schedule this custom action on the "Next" button of the "FolderDlg" dialog:
PSCA.png
PSCA.png (173.41 KiB) Viewed 5945 times

This way, until the path will be without space characters, the user will not be able to further proceed.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Deepak Singh
Posts: 13
Joined: Tue May 12, 2020 12:05 pm

Re: Restrict users not to add spaces in the installation path

Hi Catalin,

Instead of calling the custom action on next button can we add the execution of this custom action on Edit box, so that whenever user browse a path with spaces the message is displayed even before pressing the next button.

Thanks,
Deepak
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Restrict users not to add spaces in the installation path

Hello Deepak,
Instead of calling the custom action on next button can we add the execution of this custom action on Edit box, so that whenever user browse a path with spaces the message is displayed even before pressing the next button
Unfortunately, I'm afraid that is not possible.

Please let me know if you have any other questions and I will be glad to assist.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Deepak Singh
Posts: 13
Joined: Tue May 12, 2020 12:05 pm

Re: Restrict users not to add spaces in the installation path

Hi Catalin,

Can we keep the message box always in front of the advanced installation dialog box. I have observed that the waiting symbol is displayed until the ok button or the cancel button of the message box is pressed to move to further installation. Can it be possible that the message box always remain on top of the installation dialog box w.r.t advanced installer. If user clicks on the advanced installer dialog then the message box goes behind the installation window, is it possible to always keep that message box in front of the advanced installer window ?
Deepak Singh
Posts: 13
Joined: Tue May 12, 2020 12:05 pm

Re: Restrict users not to add spaces in the installation path

Hi Calatlin,

Can we add the message on the powershell inline script from dictionary so that whenever the locale is changed the mesaage displayed will be as per the dictionary. For example lets say if the system locale is in Chinese then the message must be displayed in Chinese?

Thanks and Regards,
Deepak
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Restrict users not to add spaces in the installation path

Hello Deepak,

Yes, that should be possible if you display the message through a property.

For instance, in "Install Parameters" page, create a property that will contain the desired message.

After doing so, please go to "Translations" page --> "Project Strings" tab --> click on "Select..." --> "Properties".

This should display your property there and you can localize it accordingly.
localization.png
localization.png (68.21 KiB) Viewed 5860 times
After doing so, you should retrieve the value of the property in your PowerShell script, i.e.:

Code: Select all

$message = AI_GetMsiProperty MY_PROPERTY
message.png
message.png (242.13 KiB) Viewed 5860 times

Additionally, if you are interested, I've found another method of achieving the same without a PowerShell script. For more information, please have a look over the "Use original installation path when upgrading": possible to have a dependency here" thread.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Deepak Singh
Posts: 13
Joined: Tue May 12, 2020 12:05 pm

Re: Restrict users not to add spaces in the installation path

Hi Catalin,

Thanks for your reply surely it will help. Actually the concern is if the installation path have spaces and if we press ok or cancel button of the message box the Next dialog in the MSI installation gets popped up, is it possible to add a cancel button in the message box so that if user clicks on the cancel button the same installation path dialog(FolderDlg) is displayed again and user gets a chance to remove the spaces in the path.

Thanks and regards,
Deepak
Catalin
Posts: 7845
Joined: Wed Jun 13, 2018 7:49 am

Re: Restrict users not to add spaces in the installation path

Hello Deepak,

Honestly, in this case, I believe it should be better if you followed the solution I've given in the thread linked above.

Here are the steps:

- add a messagebox custom action, without sequence (so we can schedule it from a dialog control)
MsgBox.png
MsgBox.png (89.76 KiB) Viewed 5783 times
- in "Dialogs" page, on "FolderDlg" dialog, add the custom action as an event under the "Published Events"
ExecuteAction.png
ExecuteAction.png (84.94 KiB) Viewed 5783 times

Basically, the logic is as it follows:

- if path contains spaces ==> spawn the messagebox

- go to the next dialog only if the "OK" button was not pressed (the property associated with it is empty)

- set the property to empty

Let's consider your path is as it follows:

Code: Select all

C:\My folder
The setup will see it contains space and it will spawn the messagebox. When the OK button is pressed, the BTN_PRESSED property is set. Since this property is not empty, it will not proceed to the next dialog. Then the property is set to empty.

When the user presses "Next" once again after removing the space characters from the path, the setup will check and see that APPDIR does not contain any more space characters and, since the BTN_PRESSED was set to empty manually by us, it will proceed to the next dialog.

Hope this helps!

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

Return to “Common Problems”