2011-07-27 77 views
7

我正在为Visual Studio 2008(针对C#项目设置&“部署”>“安装项目”)开发的自定义安装程序工作。我想在安装完成后运行一个批处理文件(* .bat)。我怎样才能做到这一点?如何在安装完成后运行批处理脚本?

+0

我想知道为什么VS安装程序允许我使用那里DLL exe js vbs只。 – Cynede

回答

6

您将不得不扩展Installer类并覆盖Committed事件。

这是example。希望你能够找到如何在C#中运行.bat文件。

[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是另一种选择。 Here是一个类似的线程。

1

您可以使用cmd.exe运行批处理文件,无论如何它是执行批处理文件。

以此方式开始:cmd.exe /c <path-to-batch>\batchfile.bat

+0

在2010的安装程序中 - 无法更改cmd.exe的源路径,当cmd.exe的xp位置位于c:\ winnt \ system32中时失败,但Windows 7位于c:\ windows \ system32我很难过 – pithhelmet

+0

@pithhelmet'%comspec%'环境变量存储'cmd.exe'的完整路径。 '%windir%'指向Windows目录,则'%windir%\ system32 \ cmd.exe'正确指向'cmd.exe'。即使Windows不在'C:'驱动器上,它也能工作。由于'system32'列在'PATH'环境变量中,因此可以省略'cmd.exe'的完整路径。 –

相关问题