Solved

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

Posted on 2014-11-21
44
437 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
0
Comment
Question by:SHANCHAT972
  • 25
  • 19
44 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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).
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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).
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
I would do this:

since script does have access to the session object, I'd do it by script.

The script would launch whatever executable needs to be launched to configure the database, and wait until it's complete. Once complete, the script verifies that the database is configured, by running 2-3 commands to connect to the database and run some sql statement. If no error, then the script sets the property the button's enable/disable looks at, using Session object.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
Sorry if I sound dumb, but I am not sure how to create the script you are talking about.
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
Create the script as .vbs file, and add to VS Setup and Deployment project using menu View/Editor/Custom Actions. In the script, you have access to the properties of your installation by Session.Property("<property-name>"). My article http://www.experts-exchange.com/Programming/Installation/A_3493-How-to-Report-Result-of-Installation-in-Active-Directory-Deployment.html has an example.
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
I re-read this thread and realized that you are not using Visual Studio setup and deployment project. In Orca, you need to create custom action 5 or 6, details at http://msdn.microsoft.com/en-us/library/aa372048%28v=vs.85%29.aspx .
0
 

Author Comment

by:SHANCHAT972
Comment Utility
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
The article with images is also here:
http://www.vadimrapp.com/article5.htm

But I showed the article only as an example of the script, how the script accesses properties from Installer session. Obviously, the goal in the article has nothing to do with yours, so  you don't need dbreg and functions etc. It was only to illustrate transfer of the information between Installer and script.

Here's a sample installation I created for you that illustrates the technique of validating code in a dialog. The script sets property "validcode" if another property equals 33, then the value of "validcode" becomes the condition of the button Next advancing to the next dialog.

You'll have to repeat code validation at the execution phase, and allow entering the code from command line, because otherwise all your protection will be easily bypassed by running msiexec /q .
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
"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.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
Yes; you return anything from the script to the installation by using Properties. Then use that property in the condition for the button.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
Vadim Rapp. Thank you so much for your valuable comments.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
1. vbscript can be picky about variable types. replace <>1 for <>"1".  Also assume that it's all case-sensitive. You can check in the detailed log, it will show property value after custom action. You have my sample that works, so you can always compare what's different (i.e. what you have screwed up by the changes so it stopped working :-)

2. This is all quite delicate stuff. Before doing actual work, experiment on some trivial simple installation created just for this purpose, like the one I uploaded. Actually, experiment on mine.

3. re. exception, most likely it's security-related. You have authentication=sspi in connection string. I recommend to configure sql server to accept mixed authentication, create sql server logon just for this purpose, with permissions minimally necessary for this query, and use it in the script.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:SHANCHAT972
Comment Utility
Thanks. I will try and get back to you.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
No. Anything you want to pass, you pass through the properties.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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)
0
 
LVL 40

Assisted Solution

by:Vadim Rapp
Vadim Rapp earned 500 total points
Comment Utility
registryString = "HKEY_LOCAL_MACHINE\SOFTWARE\Company\Application\Version\KeyName\ValueName"
Set objRegistry = CreateObject("WScript.Shell")
value = objRegistry.RegRead(registryString)

if you need to read default value, then ...\KeyName\"

For the things that don't depend on Session object of the installation, you can create file tryme.vbs in notepad and try it right from your desktop.

Or you can ask Installer find it for you. What it will find it will put into a property. The advantage is that you can condition the installation on that property, i.e. if your registry key is not found, then the installation is terminated. There are many other possibilities as well, for example, if the installation has an application and a macro for Word, enable the latter only if Word is found in the system.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
Thanks :-)
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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?
0
 

Author Comment

by:SHANCHAT972
Comment Utility
Error says object not found. Error #424
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
Comment Utility
This problem was discussed at various forums, but there's no definite solution. One was in the developer using curly quotes instead of regular, so carefully check the spelling in the custom action, better erase and re-type by hand.

If that does not help, then as I said, the next step is running Process Monitor and seeing what's going on. Create trivial installation with the following vbscript custom action in the very beginning:

msgbox "ready"
set o = createobject("wscript.shell")

and make sure it fails like it does in your real installation. Then when during the installation you see "ready", start monitoring and quickly hit "ok" in the message, so it fails.  Then you will have to analyze the output.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
ok thanks. I will try this and get back to you.
0
 

Assisted Solution

by:SHANCHAT972
SHANCHAT972 earned 0 total points
Comment Utility
ok I figured it out and I cannot believe it.

------------------------------------------------------------------------------------------------------------
Below code gives an error:
------------------------------------------------------------------------------------------------------------

      strMessages = ""
      NewState= -1
      readFromRegistry=" "

      Set objRegistry = createobject("wscript.shell")

      If Err.number > 0 then
            strMessages = "Error - Registry Access"
            Session.Property("strError") = strMessages
            MsgBox ("Error 1 - #" & CStr(Err.Number) & " " & Err.Description)
      Else
            strMessages = "Success - Registry Access"
            MsgBox  strMessages
      End If
------------------------------------------------------------------------------------------------------------



------------------------------------------------------------------------------------------------------------
This code works fine:
------------------------------------------------------------------------------------------------------------
      Set objRegistry = createobject("wscript.shell")

      If Err.number > 0 then
            
                  NewState= -1
            

            strMessages = "Error - Registry Access"
            Session.Property("strError") = strMessages
            MsgBox ("Error 1 - #" & CStr(Err.Number) & " " & Err.Description)
      Else
            
                  strMessages = ""
                  NewState= 1
                  readFromRegistry=" "
            

            strMessages = "Success - Registry Access"
            MsgBox  strMessages
      End If
------------------------------------------------------------------------------------------------------------
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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.
0
 

Author Closing Comment

by:SHANCHAT972
Comment Utility
Thank you a lot for your help Vadim Rapp. :-)
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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??
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
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.
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
Comment Utility
> Do you want me to create another question thread for this?

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

Author Comment

by:SHANCHAT972
Comment Utility
ok sir. Here is the link to the question:

http://www.experts-exchange.com/Programming/Installation/Q_28623080.html


:-)
0
 

Author Comment

by:SHANCHAT972
Comment Utility
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:

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28622725.html
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now