Link to home
Start Free TrialLog in
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

VS installation project with serial number validation using C#.Net Library

I want to set up a custom installer for my project.  For this I am using Orca to edit the web dialogs for the installer.

Now I want to set up a validation of the Organization Name and Serial Number using my C#.Net Library (DLL) in "VsdCustomerInfoDlg.wid".

Please tell me if there is a way to do this as till now I can see only solution for C++ based DLL online.


Thanks
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

You can take a look at the tutorial at http://blogs.msdn.com/b/wriju/archive/2009/05/21/setup-and-deployment-custom-action-to-capture-user-input.aspx ; however, we don't recommend doing it because:

1. anybody will be able to modify the installation and remove this checking, for example using the same Orca.

2. this method is based on the key coming from the user dialog. However, the installation can be run without user interface, using switch /qn. Accordingly, you have to provide the means to supply the key without UI, and additional checking for the key during execution phase of the installation.

3. Later down the road it will become even more complicated in case of upgrade to the next version, when you will want to bypass entering the key, so you will have to introduce additional conditions on when to ask for it. There may be other scenarios when you'll want to bypass it, such as various demo's, troubleshooting, and more.

For those reasons, we recommend to implement handling serial number by the application. Validating serial number by the installation is difficult even with professional installation-authoring tool that has access to all features of Windows Installer.
Avatar of Arikkan

ASKER

I can modify the "Register User" dialog page to launch an application (I can link EXE of WinForms application) to check the correct Key. This works as far as I tried. The application also run well.

But then how do I communicate a flag to the installer so that NEXT button is disabled/enabled based on a Flag in the launched application (WinForms).
Communications between custom actions (which your external application will be) and Installer session are being done by means of Installer's Properties. Custom action has access to the Session object (http://msdn.microsoft.com/en-us/library/aa367457(v=vs.85).aspx), so it will set Session.Property("propertyname") = value; then the buttons in the dialog will have show/hide or enable/disable conditions based on that property (http://msdn.microsoft.com/en-us/library/aa368035(v=vs.85).aspx).
Avatar of Arikkan

ASKER

Thanks, I am able to check the enable/disable of the Next button on Installer with the Custom Property check in "ControlCondition" table.  

BUT,
The EXE that I am using is for WinForms and that has no session object.
So how to access the property that needs to be changed at launched external application?

Please guide.
Unfortunately, according to the 1st article I cited in my previous comment, "You cannot access the current installer session from custom actions that call executable files launched with a command-line, for example, Custom Action Type 2 and Custom Action Type 18." Must be either dll, or vb/jscript

> Please guide.

I practically guarantee that later down the road you'll come to the conclusions from my first comment. I have a customer who 2 years ago also fought tooth and nail to have all reg key-related work in the installation. I warned, but did as she wanted. Now she finally implemented it in the application, and more billed hours were spent to remove all that from the installation.
Avatar of Arikkan

ASKER

ok. I also have a custom page (Used the 'User Registration' Page as base) where the button ("Configure Database Now....") is used to call external application to configure the Database. (I am using winforms for the back end application).

I don't want user to proceed with the installation if the Database has not been configured (By disabling the NEXT Button).

That is another reason for me to find the way to communicate the back end status (DB config status) with the installer (To Enable/Disable the NEXT button).

I need to find any way possible to do this.

Help !!!!

User generated image
SOLUTION
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

Sorry if I sound dumb, but I am not sure how to create the script you are talking about.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

As per my understandfing of the article, I have done the following:

1. Added script to the "Binary" Table in Orca.

User generated image
2.  Created custom actions for the 3 functions in VBScript in "CustomActions" Table in Orca.
==>
(All 3 actions have the Name we gave in the binary table shown in the Source column.  For the type, type 6 indicates a regular custom action; type 1542 and 1286 respectively specify execution on Commit and on Rollback in the deferred phase. Column Target points to the respective function within our vbscript.)

User generated image
3. Created condition [KeyValidated] to Enable/Disable the NextButton in "ControlCondition" Table in Orca.

 User generated image
4. Added rows in "ControlEvent" Table in Orca...... Not sure if this is correct as I need to set value of variable [KeyValidated] depending on Success/Failure of the action on clicking "RegisterButton".

Please guide....


User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

I agree that your solution would be perfect for me if I could set the session object in my application (called at the backend).
But since I am using WINFORMS, I have hit a brick wall as it does not allow setting of session object.

But since the VBSCRIPT can access the database, it might allow me to read a table in database to return a value.
Then  I can use this return value to set the variable in ORCA.

Could I use this as my CustomAction? :
Action: CheckAdvanceToNext
Type: 6   ???
Source: dbreg1 (Name from BINARY table for VBSCRIPT function)
Target:  Session.Property("validcode")= [VBScriptFunctionNameToTestDatabaseValue]


User generated image
So, if I understand correctly, in the beginning of the installation you want to validate the code using lookups in the database that will be installed by that installation?

If your validation is really based only on the database, then your custom action, which runs in the user interface phase of the installation, before anything even started to actually install,  would have to install the database by itself, and then probably to remove it so the installation would install it again. Sounds little crazy, doesn't it.
Avatar of Arikkan

ASKER

The database server installation is a pre-requisite and will not be installed by my installer.
It will only create database for use in the application.

But for the validation I can create a table in TEMPDB as well. And this value will be checked after the database creation phase. Would that be a wrong practice?
"And this value will be checked after the database creation phase."

Let's say the checking has failed. What will you do? The installation has finished.
Avatar of Arikkan

ASKER

Can I just return a "0"/False from the VBScript (Checking function) to indicate problem in database creation?

In this case the Next button will be disabled and user cannot go forward on Installation at all.
Yes; you return anything from the script to the installation by using Properties. Then use that property in the condition for the button.
Avatar of Arikkan

ASKER

Vadim Rapp. Thank you so much for your valuable comments.
Avatar of Arikkan

ASKER

I am having 2 issues:

1. I am not able to set the session variable in the VB Script. It gives me an exception in the "CustomAction" table.
(I did not attach screenshot for this custom action)

Here in CustomAction I tried this code. But I got an exception while reading the session variable "theCode" which was set in VBScript:

parm = Session.Property("theCode")
msgbox "theCode=|" & parm & "|"
If parm="1" Then
      Session.Property("KeyValidated")="1"
      msgbox "set KeyValidated=1"
Else
      Session.Property("KeyValidated")="0"
      msgbox "set KeyValidated=0"
End If



The VBScript is as below.
User generated image
User generated image
2. I tried to set the variable "KeyValidated" in custom action so that I could Enable / Disable the next button. (See "CustomAction" and ControlEvent" tables below). But the variable is not setting to "1". Not sure what I am missing. This should have been a very straightforward code.
User generated image
User generated image
Variable Value:
User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

Thanks. I will try and get back to you.
Avatar of Arikkan

ASKER

You were right. I was making mistake in the Variable Types (1 vs "1") in VBScript. That was the cause of the exception. Thanks a ton for your help.   :-)


Now I would like to ask you something more. Is there a way to pass parameters to the VBScript that we are calling in the "CustomAction" table. See below....

 User generated image
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

Thanks.

Could you tell me what is the best way to read registry  values in the VBScript code that we are calling above?

I tried to use the below code and I am getting error in the VBScript :

      Dim objRegistry, value, _registryString
      Set _registryString = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Company\\Application\\Version\\KeyName";

      Set objRegistry = CreateObject("WScript.Shell")
        value = objRegistry.RegRead(_registryString)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

Thanks :-)
Avatar of Arikkan

ASKER

Thanks. I can run the script on command line using "CSCRIPT". The script works as expected..

But somehow when I call the same script in the installer, I am not able to get past the below code, this line is giving me an error:

Set objRegistry = CreateObject("WScript.Shell")

Any ideas?
No way, this command is supposed to work in all versions of Windows. Troubleshooting probably would involve tracing by Process Monitor and seeing what fails. What is the error?
Avatar of Arikkan

ASKER

Error says object not found. Error #424
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan

ASKER

ok thanks. I will try this and get back to you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you created test installation with this code and it failed, can you upload it for us to try? and tell the o/s where it happened. Rename the file from .msi to .txt to bypass security (e-e does not mind, but refuses to address this either).

By the way, for your code beginning with if err.number to work, you need to put on error resume next, otherwise the error terminates the execution so the piece if err.number>0 would never run.
Avatar of Arikkan

ASKER

Thank you a lot for your help Vadim Rapp. :-)
Avatar of Arikkan

ASKER

I am having a peculiar problem in the installer.

I have 2 windows that need to call EXE files (For external application) and then VBSCRIPT to ENABLE/DISABLE the next button based on condition (Session Variables read from VBScript).

The first Window works just fine. But the second window seems to be using the VBScript code from the first window.
It throws an error code that is only available in the first window VBScript. How is that possible?


When I run the VBSCRIPT in the second window separately on Command Prompt using CSCRIPT /i , it works perfectly fine and I put messageBoxes on it for testing. I can see all messageBoxes. But these don't display in second window in Installer. So confusing.

What is the catch here?
I don't understand. What do you mean by "windows"? ("I have 2 windows that need to call EXE files") . Maybe you meant custom actions??
Avatar of Arikkan

ASKER

Hey there, Hope all is well!

You were a great help in resolving my previous issue.

I'm stuck with banner bitmap image on installer project. I've added custom dialog and added a image in it to show as banner bitmap, but image doesn't show up on machines other than development machine.

When running the installer banner image shows up just fine on development machine, but it's not showing up on other machines(QA).

Any ideas as what could be blocking the image to not show up?
Probably depends on what msi-authoring tool you use. Look at the table Control, find the control where you expect the image, make a note of the value in the column "Text", find it in the table Binary, and see if you can export the binary data into a bmp.
Avatar of Arikkan

ASKER

ok thanks Vadim Rapp. You are very helpful as always :-)
I will try it and get back to you.
Do you want me to create another question thread for this?
> Do you want me to create another question thread for this?

does not matter to me, but E-E probably does :-)
Avatar of Arikkan

ASKER

Hey Vadim Rapp,  I was able to resolve custom image issue.

Now I'm having different issue about publisher name on setup.exe file. if I run it as an administrator, it always shows "Unknow" as publisher. i want to change it to my company name:

I've already created a question for this. here's the link to the quesiton:

https://www.experts-exchange.com/questions/28622725/How-to-change-Publisher-in-asp-net-websetup-project-setup-exe.html