We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

Validate IP Address ...

Hello,

I have generated a custom dialog and created a masked edit field with "###.###.###.###" to present a dialog for requesting the user to enter the IP address.

However, I would also like to validate that the IP address that was provided in the correct format (e.g. no values greater than 255.255.255.255).

Additionally, when an IP address is provided, the output appears as the following: 10 .10 .2 .1

The application I am forwarding this input to will not recognize the IP with the spaces between the numbers. Is there a way to fix this?

Thanks in advance.

Trey
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

I'm afraid that this cannot be done by using a masked edit because the user must fill the template (for example he should set it to 010.010.002.001 instead of 10.10.2.1).

The solution is to use a simple Edit box in which the user will input the full IP (for example "10.10.2.1"). You can validate if the IP is correct by using a custom action scheduled as a published event for the next button on your custom dialog.

You can read more about custom actions here:
http://www.advancedinstaller.com/user-g ... -page.html

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

I have found another nice work around for validating an IP Address.

I can set a control condition for the "Next" button of the dialog I am requiring an IP to be typed in.

I have set 2 conditions as the following:

1.

Condition: (DIALOG_IP > "255.255.255.255") OR (DIALOG_IP < "1.1.1.1") OR (PASSWORD = "")
Action: Disable

2.

Condition: (DIALOG_IP < "255.255.255.255") OR (DIALOG_IP > "1.1.1.1") OR (PASSWORD >< "")
Action: Enable


This works great! But there is one problem. The condition does not get validated until an action is performed.

So for example, I enter a valid IP in the DIALOG_IP field and provide a password that meets all of the conditions to enable the next button, but the next button does not become enabled until I hit the tab button to Cancel or Back.

So is there anyway to have it perform immediate validation?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,
This works great! But there is one problem. The condition does not get validated until an action is performed.
I'm afraid that this is not supported by Windows Installer. The control (the "Next" button) is not updated until the edit box loses the focus (another control is selected).

The solution is remove the Control Conditions and use a custom action which will allow the user to go to the next dialog only if a correct IP has been entered. There is a similar discussion on the forum, please take a look:
http://www.advancedinstaller.com/forums ... php?t=4843

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

Ok, so my previous suggestion didn't work so well. The workaround you indicated seemed to work much better than defining a control event. But the IP validation conditions didn't seem to work so well.

So now I am thinking to implement a custom application I have that verifies the IP format provided.

How can I incorporate that into the installer?

Is there a way I can control the Next button based on the output of an application?

Thanks!

Trey
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,
So now I am thinking to implement a custom application I have that verifies the IP format provided. How can I incorporate that into the installer?
You can add this custom action as a DoAction Published control event for the "Next" button. Note that before this, you must add the custom action under "UI Custom Actions" in the "Custom Actions" page.

You can read more about custom actions here:
http://www.advancedinstaller.com/user-g ... -page.html
Is there a way I can control the Next button based on the output of an application?
Yes. In your custom action (application) you set a public property. This public property will be used as a condition for the "Next" button.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ssearles
Posts: 65
Joined: Tue Oct 30, 2007 12:54 pm

wouldn't adding a custom "Validate" button that itself would be required to get the "Next" button to activate also work? It would allow for the change of focus and fire off your custom action, wouldn't it?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Yes, if you use a custom "Validate" button then the focus will be changed and the "Next" button will be enabled.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

I have tried what you suggested Cosmin, but I am still having difficulty.

So I have modified my custom application to set an environment variable if an invalid condition holds, but the installer will not see the variable.

If I set the variable manually before reaching the dialog, the installer sees the variable and behaves accordingly. But it seems that the installer does not see the variable that is set directly after the custom application executes.

I have also tried this solution using a registry value. I get the same behavior.

Any suggestions?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Please note that environment variables are not available in the process which creates them. Since your environment variable is created by the MSI installation process, you cannot use it in the installation.
I have also tried this solution using a registry value. I get the same behavior.
Please note that the registry values are created during the "WriteRegistryValues" standard action (which is scheduled after the files are installed), therefore you cannot set and use a registry value in the User Interface.

Note that in order to pass the validation to the installation UI, you need to set a Windows Installer public property from inside the custom action. In C++ DLLs you can use the MsiGetProperty/MsiSetProperty functions and in VBScript you can use the Session.Property method. You can read more about these functions here:
http://msdn2.microsoft.com/en-us/library/aa371681.aspx
http://msdn2.microsoft.com/en-us/library/aa370134.aspx

In a VBScript custom action you can use the Session.Property object:
http://msdn2.microsoft.com/en-us/librar ... S.85).aspx

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thenefield
Posts: 68
Joined: Thu Dec 06, 2007 6:19 pm

Thanks Cosmin for your advice.

It now works using VBscript.

I also had to add an invisible text box in the dialog to store the return value of the VBscript. The value in that text box can then be used to validate conditions for moving to the next dialog.

I have to say that the references you provided to the Microsoft website was no help because it provided no examples for utilizing the session.property function. But I found a good reference here:

http://64.233.167.104/search?q=cache:9R ... n.property

---------CODE---------

Setting a Property

Sub SetAProperty_fun
Session.Property("PROPERTYNAME")="property value"
MsgBox Session.Property("PROPERTYNAME")
End Sub

Getting a Property

Sub GetAProperty_fun
dim szStringVal
szStringVal = Session.Property("PROPERTYNAME")
MsgBox Session.Property("PROPERTYNAME")
End Sub

---------CODE---------

I hope someone else may find this useful.

Best regards,

Trey

Return to “Common Problems”