Serial Validation using "user defined validation" - Advanced Installer Community
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Serial Validation using "user defined validation"

Hi,
I have a big problem with serial validation, I made a new project using advance installer, I want to make a serial for this program using my custom code.
I made the following :
1-go to visual studio 2010 --> make a project of type WIX --> C# custom action project --> make a function named
public static ActionResult validateSerial(string str_serial)
{
if (str_serial.ToUpper() == "1111111111")
return ActionResult.Success;
else
return ActionResult.Failure;
}
build the project
2- go to advance installer --> files and folders --> windows volume --> temporary > add files
and choose the dll I have made(Serial.CA.dll)
3-then go to serial validation check on use serial validation and make the template like this <##########>
choose user defined validation --> choose the file (Serial.CA.dll) but my function I had made doesn't appear in the combo box Is this a problem ?
I wrote the function name "validateSerial"
4-go to custom actions --> Rclick on install and choose the 2nd option 'New installed custom action" and choose (Serial.CA.dll) the function name does't appear here too ??? I wrote it by my hand
5-build the project and test it
a message box with the text "There is a problem with windows installer package, a dll required for this install to complete could not be run. Contact your support or pachage vendor".
please I wanna help ASAP
thanks in advance
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Serial Validation using "user defined validation"

Hi,

Have you followed the steps from our article for creating the DLL file?
http://www.advancedinstaller.com/user-g ... rp-ca.html

Also, please note that you don't need to add the DLL as temporary file in Files and Folders page, just select it from Serial Validation page.

To get the serial number from the installer you will need to get the value of the property PIDKEY from your code. The following
thread has an example on how to get the value of a property:
http://www.advancedinstaller.com/forums ... 751#p47436

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

Hi,
If I didn't add the dll to temporary filem it doesn't appear when I click new installed custom action ??
and u didn't answer me about the function name that doesn't appear in the serial validation form ??
I made the whole steps in the article but it doesn't work :(
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Serial Validation using "user defined validation"

Hi,
If I didn't add the dll to temporary filem it doesn't appear when I click new installed custom action ??
Custom actions are recommended to be added as attached, not installed, so they can be used at any moment of the install/uninstall process.
and u didn't answer me about the function name that doesn't appear in the serial validation form ??
I'm not sure why this is happening, if you follow all the steps from that article the DLL should export its function name.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

please I don't get the point of these words

"To get the serial number from the installer you will need to get the value of the property PIDKEY from your code. The following
thread has an example on how to get the value of a property:
viewtopic.php?f=2&t=19751#p47436 "

and didn't understand the purpose of this URL, Is there is another clarification
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Serial Validation using "user defined validation"

I noticed in your code that you pass a parameter "string str_serial" to your function. This is not correct, as
Windows Installer will not pass this parameter to your function when it calls it.

The function must have the same signature as the one from our article, therefore the same parameters passed, i.e. "Session session".

Probably this is the reason the function was not detected when you added the DLL as a custom action.
please I don't get the point of these words
"To get the serial number from the installer you will need to get the value of the property PIDKEY from your code.
You need to get the value of the serial number from the property PIDKEY, as we do in our C++ sample.
http://www.advancedinstaller.com/user-g ... n-dll.html

This is how the installer can communicate with custom actions, only through properties.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

I can't find words to thank you, finally the function name appears finally :)
but I have another question, How can I get the "Windows Installer property named PIDKEY" using C# code ?
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Serial Validation using "user defined validation"

Hello,

The following example demonstrates how to get or set an installer public property from a C# custom action:

Code: Select all

public static ActionResult CustomAction1(Session session)
{
// sending message to installation log
session.Log("Begin CustomAction1");

// getting a property
YourVariable = session["YOUR_PROPERTY"];

// setting a property
session["YOUR_PROPERTY"] = "YOUR_VALUE";

return ActionResult.Success;
}
All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

Hi,
I made a function like this

Code: Select all

public static ActionResult OrbitsITSerial(Session session)
        {
            if (session["PIDKEY"] == "111")
                return ActionResult.Success;
            else
                return ActionResult.Failure;
}
but if I write the serial number valid or invalid, after writing the serial number and pressing next the attached file appears as a dialog.

Do you know where is the error ?
Attachments
Error file
Error file
2011-11-02 11-43-24 AM.png (66.17 KiB) Viewed 21433 times
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Serial Validation using "user defined validation"

Hello,

Here is how to debug your C# custom action and get past this:
  • add some code for displaying a message box at the beginning of your custom action:

    Code: Select all

    public static ActionResult CustomAction1(Session session)
    { 
      // display message to allow attaching the debugger
      MessageBox.Show("Please attach a debugger to rundll32.exe.", "Attach");
     
      // sending message to installation log
      session.Log("Begin CustomAction1");
      .
      .
      .
    
  • Since you will use MessageBox, make sure you have a reference to System.Windows.Forms.dll
  • Add a breakpoint on the next line of code, after your message box code
  • Rebuild your custom action project with Visual Studio
  • Rebuild your Advanced Installer project
  • Run the installation using "Run and Log" from Advanced Installer
  • When the message box displays, go to Visual Studio project > Tools > Attach to Process…
  • From the Available Processes list select the process with the name "rundll32.exe" and title "Attach"
  • Click Ok on the message box in your installation
  • The breakpoint you set earlier should now be activated in VS
While debugging the custom action after implementing the above steps, you can observe the property changes in the Log pane of Advanced Installer.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

Hello,
Thanks for the illustration, it helped me but I still have a question, after this how can I stop the installtion if the serial is invalid or complete it if it is valid,
the function I used

Code: Select all

if (session["PIDKEY"] == "111")
            {
                return ActionResult.Success;
            }
            else
            {
                 return ActionResult.Failure;
            }
doesn't affect my installtion regardless the return value (true or false)
thanks in advance
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Serial Validation using "user defined validation"

Hi,

This operation is automatically handled by advanced Installer, all you have to do is to set the property SERIAL_VALIDATION to "TRUE" or "FALSE",
based on the serial entered by the user.

So, if the user enter a valid serial then set the property to "TRUE", otherwise to false. As we do in our C++ sample:
http://www.advancedinstaller.com/user-g ... n-dll.html

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

Hi,
Thanks for your reply, I made it but the dialog still appears, this is my code

Code: Select all

[CustomAction]
        public static uint OrbitsITSerial(Session session)
        {
             if (session["PIDKEY"] == "111")
            {
                session["SERIAL_VALIDATION"] = "TRUE";
                return 1;
            }
            else
            {
                session["SERIAL_VALIDATION"] = "FALSE";
                return 0;
            }
     
        }
I can't get the error, I have debugged the code and it is running smoothly !!!!!!
Hanan Ali
Posts: 20
Joined: Tue Nov 01, 2011 10:11 am

Re: Serial Validation using "user defined validation"

I guess the error is this part of advanced installer log

"Action 10:24:35: AI_VALID_SERIAL.
Action start 10:24:35: AI_VALID_SERIAL.
MSI (c) (28:20) [10:24:35:314]: Invoking remote custom action. DLL: C:\Users\Hanan\AppData\Local\Temp\MSI5D4F.tmp, Entrypoint: OrbitsITSerial
Action ended 10:24:35: AI_VALID_SERIAL. Return value 3.
DEBUG: Error 2896: Executing action AI_VALID_SERIAL failed.
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2896. The arguments are: AI_VALID_SERIAL, ,
Action ended 10:24:35: WelcomeDlg. Return value 3.
MSI (c) (28:6C) [10:24:35:764]: Doing action: FatalError
Action 10:24:35: FatalError.
Action start 10:24:35: FatalError.
DEBUG: Error 2826: Control BottomLine on dialog FatalError extends beyond the boundaries of the dialog to the right by 3 pixels
The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2826. The arguments are: FatalError, BottomLine, to the right
Action 10:24:35: FatalError. Dialog created
Action ended 10:24:37: FatalError. Return value 2.
Action ended 10:24:37: INSTALL. Return value 3."

Return to “Common Problems”