Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a batch script after installation is finished?

I'm working for a custom installer developed in Visual Studio 2008 (Setup & Deployment > Setup project) for a C# project. I'd like to run a batch file (*.bat) after installation is finished. How can I do that?

like image 764
Donotalo Avatar asked Jul 27 '11 04:07

Donotalo


People also ask

How do I get a batch file to run automatically after reboot?

The easiest way to run a batch file on a system startup is to place it in the Windows “Startup” folder or drop there a shortcut. Programs placed in this folder are meant to run automatically whenever the computer boots up.

How do I run a batch file execution?

To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.

How do I run a batch file while installing?

In the "File System" view (right-click on the project in Solution Explorer->View->File System), add the batch file you want to execute and cmd.exe (C:\Windows\System32\cmd.exe) Open the "Custom Actions" view (right-click on the project in Solution Explorer->View->Custom Actions)


2 Answers

You will have to extend the Installer class and override the Committed event.

Here is an example. Hope you will be able to find how to run a .bat file in C#.

[RunInstaller(true)]
public class ServiceInstaller : Installer
{
    string strServiceName = "MyServiceName";

    public ServiceInstaller()
    {
        // .............

        this.Committed += new InstallEventHandler(ServiceInstaller_Committed);
    }

    void ServiceInstaller_Committed(object sender, InstallEventArgs e)
    {
        // Run your batch file
    }
}

Custom Install Action is another option. Here is a similar thread for that.

like image 125
CharithJ Avatar answered Oct 01 '22 20:10

CharithJ


You can run a batch file using cmd.exe, anyway it is what executes batch files.

Start it this way: cmd.exe /c <path-to-batch>\batchfile.bat.

like image 37
Alexey Ivanov Avatar answered Oct 01 '22 20:10

Alexey Ivanov