Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

Visual Studio Setup and Deployment Project and .bat files???

Okay, Microsoft has a pretty slick method of deploying projects, especially with the 'prerequisites' settings.

However, I need to run an SQL script at the end of the installation to build a new database for SQLExpress.

Q. Is there any way to run a .bat or .sql within the VS2005 Setup Deployment project???
0
kvnsdr
Asked:
kvnsdr
  • 4
  • 3
3 Solutions
 
gsalierCommented:
If you add an Installer.cs to your main project and override the Install and UnInstall methods
(Add the System.Configuration.Install to your project references)

using System;
using System.Configuration.Install;

namespace ExpertsExchange.Q_21804504
{
      /// <summary>
      /// Summary description for Installer.
      /// </summary>
      [RunInstaller(true)]
      public class Installer : Installer
      {
            public Installer()
            {
                  //
                  // TODO: Add constructor logic here
                  //
            }

            public override void Install(System.Collections.IDictionary stateSaver)
            {
                  base.Install (stateSaver);
                  //Write your code to execute your sql script
            }

            public override void Uninstall(System.Collections.IDictionary savedState)
            {
                  base.Uninstall (savedState);
                  //Write your code to get rid of the Sql Script
            }
      }
}
0
 
gsalierCommented:
As far as detail on how to run a script there is quite a long winded version here.

http://www.codeguru.com/csharp/.net/net_security/encryption/article.php/c9601/

The above code however is the basis for what you need to do.

Cheers
0
 
kvnsdrAuthor Commented:
Interesting, but are we talking about the same thing.

I like the VS2005 .NET 2.0 Installer Project and it's use of 'Prerequisites' (much like Click-Once).

I'm not sure how the installer.cs can install the SQL scripts like Wise or InstallSheild do....

I need something that will simiulate a simple, no-hands-on end-user install.

So when the end-user double-clicks his desktop Icon, everything is installed with nothing for the end-user to do.

Sorry if I maybe missing your point.

I'm very interested and need additional explaination.....

The word 'Override' makes me think this installer.cs may compromise the VS Installer....

Help me understand.............


 
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
gsalierCommented:
What language are you developing in?

Override is what happens when you need to perform some extra functionality in a derived class that the base class doesn't provide. If you see the base.Install(etc) is the first call in my override which basically means do what you were going to do before I do what I want to do. All the normal install stuff happens before you do your custom stuff. And your custom stuff is to run a database script against the target db.

When the installer project is installing your software, it looks for any installation code that needs to be run in the projects it has just installed. The above code is one such instance. When the msi calls this code, the base installation stuff is done before your own extra installation requirements. These can be anything from creating a new web site, installing some other project or (in your case) executing a sql script to create the necessary database for your project.

This is what would be done in vs.net 2003. Its probably still the same in 2005 but I shall check....

If you are doing this in VB.net then we have to change the code slightly.

As far as simulating a no-hands-on install, thats what this does.

A question to you would be: What will you do if the end user already has a version of SQL on their machine that has security tightly configured? You must ask them for a secure method to communicate with the database or otherwise create a new instance.... if you create a new instance on some peoples machines by default, they may not be too happy.

Is this an internal business project or an external Joe Public project?

I shall return after checking the vs2005 install procedures. Someone will probably beat me to the answer however.

Cheers

0
 
gsalierCommented:
Yep, still the same.

the following is a more detailed version of what you are trying to do.
       
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "oSql.exe";
            process.StartInfo.Arguments = "-E -S ServerName\InstanceName -i YourSqlScript.sql";
            //If you want to do it Syncronously
            process.WaitForExit();
            //Otherwise if you want to do it Asynchronously
            //process.Exited +=new EventHandler(process_Exited);
            if (!process.Start())
            {
                //Something went wrong so you may want to roll back the installation
                //base.Rollback(stateSaver);
                //Unless you are happy for the user to do there own fixes
            }
            stateSaver.Add("ScriptInstall", true);
        }
0
 
kvnsdrAuthor Commented:
Okay, I've downloaded and inspected the project from the link above:

http://www.codeguru.com/csharp/.net/net_security/encryption/article.php/c9601/

I understand they added an 'Installer.cs' into thier application project.

It's like an installer wrapped within another installer.

Q. What 'fires' the installer to do it's job?
0
 
kvnsdrAuthor Commented:
Here's another link I found concerning the Installer class!

http://www.c-sharpcorner.com/Code/2002/July/UseInstClasses.asp

Thank you all..............

><>
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now