Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

How to validate parameters in custom dialog

Using AI 7.7:
I have created a custom dialog, where I put two EditBoxes:
1. User name (property name: USER_NAME)
2. Password (property name: USER_PASSWORD)

I have created a C# program that receives these two parameters in the command line and returns success or failure if these parameters are correct for the current computer.
Now what is missing for me is:
1. I want the user to press the "next"
2. Then I will run my custom action: ValitateUser.exe "[USER_NAME]" "[USER_PASSWORD]"
3. If this custom action fails, then I want to show a MessageBox saying "Incorrect user/password", and return/stay on the dialog page.
4. If the user pressed "next" and the custom action succeeded, then move him to the next dialog.

How can this be achieved?
Many thanks, Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi Dashut,
1. I want the user to press the "next" 2. Then I will run my custom action: ValitateUser.exe "[USER_NAME]" "[USER_PASSWORD]"
Unfortunately there is problem in your design. Executable files cannot access public properties, you will need to convert your EXE to a C++ DLL or VBScript in order to have access to those properties.

Here is explained how you can call your DLL or script.
3. If this custom action fails, then I want to show a MessageBox saying "Incorrect user/password", and return/stay on the dialog page.
After this custom action create a new published event on the [Next] button with the following fields:

Code: Select all

Name: Spawn Dialog
Argument: <NewDialog>
Condition: VALID_INPUT = "FALSE"

Where "VALID_INPUT" is a public property which you will set from your script or DLL to "TRUE" if the username and password entered by the user are good and to "FALSE" otherwise.
The "<NewDialog>" from the "Argument" field means that a new spawn dialog will be created which you can edit to add the desired message.

Please let me know if you have any questions.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

Okay, I think I got it. I will call a VBScript that will have access to the USER_NAME and USER_PASSWORD properties and will set the property: VALID_INPUT.
The question is now: how do I call my c# code from VBS? Sorry for this question, but I am not familiar with VBS.

Many thanks, Dashut.
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

Here's something I created from what I found in the Internet (this is not what I want yet, but if this works, I can most probably do what I need to do as explained above/before):

Code: Select all

Function ValidateUser()

Set WshShell = WScript.CreateObject("WScript.Shell") 
intReturn = WshShell.Run("notepad.exe", 1, true)

if (intReturn = -1) then MsgBox("failed")
if (intReturn = 0) then MsgBox("success")
	
End Function
But the problem is that it's not working, and when running this script from AdvancedInstaller I get the following error:

Code: Select all

Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor.  Custom action viewer.exe script error -2146827864, Microsoft VBScript runtime error: Object required: 'WScript' Line 3, Column 1,  
MSI (c) (4C:90) [13:00:24:234]: Product: _TestDetectService -- Error 1720. There is a problem with this Windows Installer package. A script required for this install to complete could not be run. Contact your support personnel or package vendor.  Custom action viewer.exe script error -2146827864, Microsoft VBScript runtime error: Object required: 'WScript' Line 3, Column 1,  
If I remove the "Set" command like this:

Code: Select all

Function ValidateUser()

intReturn = -1
if (intReturn = -1) then MsgBox("failed")
if (intReturn = 0) then MsgBox("success")
	
End Function
it works, but I didn't run my EXE...
Can you help with this?

Many thanks, Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi Dashut,

This happens because of the way you are using the WScript object, here are more details.

The solution would be to use this:

Code: Select all

Set WshShell = CreateObject("WScript.Shell")
Instead of this:

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

A quick test shows that what you suggested works!
I'll continue to make my full changes to the VBS, so thanks!

Quick question for you: how can I run my VBS file hidden? (maybe somehow using your: <AI_CUSTACTS>aicustact.dll???)
Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi Dashut,
how can I run my VBS file hidden? (maybe somehow using your: <AI_CUSTACTS>aicustact.dll???)
I am not sure what you mean by hidden. All you have to do is to add the vbscript as an attached custom action and call it from the MSI dialogs. There is no need to use our DLL,
this contains our predefined custom actions which are not useful for you in this case.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

Yes, that's what I do, but then when I run my custom action a "dos window" opens. I want to hide this "dos window".
Is there a way to do that? (for EXE files, I use your custom action with CreateExeProcess, and that "hides" the "dos window").

Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi,
Is there a way to do that? (for EXE files, I use your custom action with CreateExeProcess, and that "hides" the "dos window").
Indeed, for EXE files our custom action is a solution. However, VBScript has its own mechanism for this. Just make a simple search on Google and you will find
a couple of options to hide the console from the script.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

Found it! Thanks. I changed from int 1 to int 0, that's from (using link: http://msdn.microsoft.com/en-us/library/d5fk67ky):

Code: Select all

intReturn = WshShell.Run(runCommand, 1, true)
to:

Code: Select all

intReturn = WshShell.Run(runCommand, 0, true)
Dashut.
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

There's another problem I have now with this.
Everything works now as expected: I have a dialog page which the user enters username and password, and once the "next" button is pressed: I call my custom action and test to verify.
If the user/pass was wrong, I spawn a dialog telling him to retry user/pass and AdvancedInstaller returns to the same dialog (of username and password).
However, I would like to delete the value the User entered in the EditBox for password... ("reset" it: since we know it's incorrect...)

What I tried to do is call another custom action BEFORE spawning my warning dialog that should clear the property: but that didn't work... (using: "Property Set With Formatted" on the same property).
I also tried in the VBScript to put "" for this property (and the VBS didn't NOT fail): but that did NOT work either!
Say I had my password: "helloworld", then I still see "helloworld" after the spawn dialog closed and I return to my dialog (for username and password) instead of a blank place to rewrite my password (editbox remains the same - or in other words - property didn't change it's value).

how can I erase the editbox value?

Many thanks, Dashut.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi Dashut,

For updating the control right after changing the value of the control's prop, you can read the following guide on how to refresh a dialog after setting a property
On the button's published events tab, you should end up with something along the lines of:

Code: Select all

<Action that sets the control's property to "{}" without the quotes. This effectively clears the property.>
<The UI custom action that refreshes the controls. Choose the right one for the type of UI you are using, as mentioned in the guide above>
<SetProperty event that sets the control's property to the value of the control's property. Something like [CONTROL_PROP] [CONTROL_PROP]. Necessary because of a Windows Installer issue>
Let me know how this went.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

Okay, here's the thing:
I tried what you offered at: http://www.advancedinstaller.com/user-g ... ialog.html
1. "With Enhanced UI" didn't work for me. Meaning I tried what you offered there in the VBS, but that didn't work: the text remained.
2. Then I tried: "Without Enhanced UI": and that worked!

However!!!! once I changed the EditBox to be "Password=true" (in the Properties -> Attributes of the EditBox): then "Without Enhanced UI" stopped working!
So I know that what you suggest works, but NOT for EditBox that is "password" (one that you don't see text when you type but ****** instead - to hide the text/password).

Another question is: when I return to the user/pass dialog: how can I set focus again on the password EditBox (so the User will not have to use the mouse to get there)?

Dashut.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: How to validate parameters in custom dialog

Hi Dashut,
when I return to the user/pass dialog: how can I set focus again on the password EditBox (so the User will not have to use the mouse to get there)?
You can do this by setting the tab order in your dialog from our Dialogs page.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Dashut
Posts: 142
Joined: Tue May 04, 2010 4:41 pm

Re: How to validate parameters in custom dialog

I did that already, and for the first time the dialog shows the focus is there.
However, if the password was wrong and I return to the dialog after a SpawnDialog message: then the focus is set on the "next" button.

So my questions remain:
1. How to set the focus back on the password EditBox.
2. (you completely forgot this one): how to clear the password field EditBox? (this problem happens if the EditBox is set to "password" mode).

Dashut.

Return to “Common Problems”