How to run a batch script after installation is finished?

给你一囗甜甜゛ 提交于 2019-12-12 10:37:47

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6839320/how-to-run-a-batch-script-after-installation-is-finished

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!