【发布时间】:2014-01-05 09:24:09
【问题描述】:
我一直在看一些关于如何创建 C# Windows 服务的教程;一切都很好,但没有人说如何让服务运行,在安装结束时,安装文件夹中的一个特定文件(在我的情况下是 hidden.vbs)(我的应用程序有 2 个项目:服务本身和设置)。 安装安装后,服务启动 PROJECT_NAME.exe 和 PROJECT_NAME.svhost.exe
如果您需要任何其他代码来帮助我,请告诉我... 这是我的 Program.cs
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
namespace PROJECT_NAME
{
[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
public ProjectInstaller()
{
InitializeComponent();
}
private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
{
new ServiceController(serviceInstaller1.ServiceName).Start();
}
}
}
Service1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace PROJECT_NAME
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void OnDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStart.txt");
}
protected override void OnStop()
{
System.IO.File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStart.txt");
}
}
}
另外,这是我的解决方案资源管理器http://i.imgur.com/wbqUGOc.png 的照片;请告诉我应该如何或在哪里导入需要服务运行的文件。
这是我第一次接触 C#,我现在不想理解它,但我要做这个服务,因为我的工作中会需要它..
【问题讨论】:
标签: c# windows service windows-services installation