我正在为一个使用Visual Studio 2008(安装和部署>安装项目)开发的自定义安装程序工作,该安装程序是为C#项目开发的。我想在安装完成后运行一个批处理文件(*.bat),请问我该怎么做?
我正在为一个使用Visual Studio 2008(安装和部署>安装项目)开发的自定义安装程序工作,该安装程序是为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
}
}
您可以使用cmd.exe
来运行批处理文件,实际上它就是执行批处理文件的工具。
按照以下方式启动:cmd.exe /c <path-to-batch>\batchfile.bat
。
%comspec%
环境变量存储了 cmd.exe
的完整路径。 %windir%
指向 Windows 目录,因此 %windir%\system32\cmd.exe
正确指向 cmd.exe
。即使 Windows 不在 C:
驱动器上,它也可以正常工作。由于 system32
在 PATH
环境变量中列出,您可以省略对 cmd.exe
的完整路径。 - Alexey Ivanov