We help IT Professionals succeed at work.

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

Arikkan
Arikkan asked
on
1,215 Views
Last Modified: 2015-02-24
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
Comment
Watch Question

CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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).
CERTIFIED EXPERT

Commented:
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).

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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 !!!!

Screen5.gif
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Sorry if I sound dumb, but I am not sure how to create the script you are talking about.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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

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

Binary.gif
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.)

CustomAction.gif
3. Created condition [KeyValidated] to Enable/Disable the NextButton in "ControlCondition" Table in Orca.

 ControlCondition.gif
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....


ControlEvent.gif
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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]


Test-MSI.gif
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
"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.

Author

Commented:
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.
CERTIFIED EXPERT

Commented:
Yes; you return anything from the script to the installation by using Properties. Then use that property in the condition for the button.

Author

Commented:
Vadim Rapp. Thank you so much for your valuable comments.

Author

Commented:
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.
VBScript-DBValueCheck.gif
Binary1.gif
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.
CustomAction1.gif
ControlEvent1.gif
Variable Value:
VariableValue.gif
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks. I will try and get back to you.

Author

Commented:
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....

 CustomAction1-ScriptWithParameters.gif
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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)
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks :-)

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
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?

Author

Commented:
Error says object not found. Error #424
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
ok thanks. I will try this and get back to you.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
Thank you a lot for your help Vadim Rapp. :-)

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
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??

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
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?
CERTIFIED EXPERT

Commented:
> Do you want me to create another question thread for this?

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

Author

Commented:

Author

Commented:
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/Programming/Languages/.NET/ASP.NET/Q_28622725.html

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.