0
我一直在關注如何創建C#Windows服務的一些內容;所有的好但沒有人說如何使te服務運行,在安裝結束時,安裝文件夾中的特定文件(在我的案例中爲hidden.vbs)(我的應用程序有2個項目:服務本身和安裝程序)。 安裝設置後,在服務啓動PROJECT_NAME.exe和PROJECT_NAME.svhost.exe使Windows服務運行特定文件
請告訴我,如果你爲了幫助我需要的任何其他代碼... 這裏是我的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的PIC;請告訴我如何或應該在哪裏導入我需要服務運行的文件。
這是我在C#中第一次,我不願意現在來了解它,而是讓這個服務,因爲我需要它在我的工作..
我覺得我不夠清楚...由於我調用了一個事件(AfterInstall),服務自動啓動。問題是服務啓動的應用程序,它是PROJECT_NAME.exe和PROJECT_NAME.svhost.exe。如果它不能被改變(我不這麼認爲),至少告訴我在哪裏編輯PROJECT_NAME.exe,所以它至少會包含我想要啓動的hidden.vbs。 – user2908353