不需要命令InstallUtil 安装windows服务
public partial class QYService : ServiceBase
{
public QYService()
{
this.ServiceName = "QYService ";
}
protected override void OnStart(string[] args)
{
Process.Start( "test.bat ");
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
------------------------------
[RunInstallerAttribute(true)]
public partial class ProjectInstaller : Installer
{
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller;
private System.ServiceProcess.ServiceInstaller serviceInstaller;
public ProjectInstaller()
{
this.serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller
//
this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller.Password = null;
this.serviceProcessInstaller.Username = null;
//
// serviceInstaller
//
this.serviceInstaller.ServiceName = "QYService ";
this.serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller,this.serviceInstaller});
}
}
-----------------------------------------------
static void Main()
{
TransactedInstaller transactedInstaller = new TransactedInstaller();
ProjectInstaller installer = new ProjectInstaller();
transactedInstaller.Installers.Add(installer);
string path = string.Format( "/assemblypath ={0} ", System.Reflection.Assembly.GetExecutingAssembly().Location);
string[] cmdline = { path };
InstallContext installContext = new InstallContext( "Install.log ", cmdline);
transactedInstaller.Context = installContext;
System.Diagnostics.Debug.WriteLine(path);
transactedInstaller.Install(new Hashtable()); //执行安装时出错
ServiceBase[] ServicesToRun;
// 同一进程中可以运行多个用户服务。若要将
// 另一个服务添加到此进程中,请更改下行以
// 创建另一个服务对象。例如,
//
// ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new ServiceBase[] { new QYService() };
ServiceBase.Run(ServicesToRun);
}
在main函数中执行安装时出错 !!!
[解决办法]
你不是就写个批处理文件啊
[解决办法]
这些不是自动生成的吗,你为什么要自己写呢
[解决办法]
关注...