2010-12-07 9 views
2

簡単なテストWindowsサービスを作成しましたが、問題が発生しました。私はWindowsサービスが初めてのので、私がこの権利を守っているかどうかわかりません。 .net 2008 Windowsサービスのインストール

namespace testWindowsService 
{ 
    public partial class Service1 : ServiceBase 
    { 
     public Service1() 
     {InitializeComponent();} 

     protected override void OnStart(string[] args) 
     { 
      FileStream fs = new FileStream(@"c:\temp\started.txt", FileMode.OpenOrCreate, FileAccess.Write); 
      StreamWriter m_streamWriter = new StreamWriter(fs); 
      m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); 

      m_streamWriter.WriteLine("Service Started on \n" + DateTime.Now.ToShortDateString() + " at " + DateTime.Now.ToShortTimeString()); 
      m_streamWriter.Flush(); 
      m_streamWriter.Close(); 
     } 

     protected override void OnStop() 
     { 
      FileStream fs = new FileStream(@"c:\temp\stopped.txt", FileMode.OpenOrCreate, FileAccess.Write); 
      StreamWriter m_streamWriter = new StreamWriter(fs); 
      m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); 

      m_streamWriter.WriteLine("Service Stopped \n" + DateTime.Now.ToShortDateString() + " at " + DateTime.Now.ToShortTimeString()); 
      m_streamWriter.Flush(); 
      m_streamWriter.Close(); 
     } 
    } 
} 

は、その後、私はプロジェクトを構築し、スタートからコマンドプロンプトを開く - > [すべてのプログラム] - > [マイクロソフトのVisual Studio 2008 - > Visual Studioツール - >のVisual Studio 2008のコマンドプロンプト。プロンプトから私は走った:

installutil C:\Users\myUser\Documents\MyServices\testWindowsService\testWindowsService\bin\Debug\testWindowsService.exe 

しかし、私はエラーを取得:

No public installers with the RunInstallerAttribute.Yes attribute could be found in the C:\Users\myUser\Documents\MyServices\testWindowsService\testWindowsService\bin\Debug\testWindowsService.exe assembly. 

私はそれをグーグルで試してみたのが、行き止まり半の回答の多くを発見しました。

ありがとうございました

+0

サービスの開始と停止を記録する必要はありません。これはあなたのために行われ、エントリはイベントログに表示されます。 –

+0

あなたの問題を解決した場合、回答を受け入れることができますか? –

答えて

4

インストーラを作成する必要があります。例を見るにはthesearticlesを読んでください。

[RunInstallerAttribute(true)] 
public class ProjectInstaller : Installer{ 
    private ServiceInstaller serviceInstaller1; 
    private ServiceProcessInstaller processInstaller; 

    public MyProjectInstaller(){ 
     // Instantiate installers for process and services. 

     processInstaller = new ServiceProcessInstaller(); 
     serviceInstaller1 = new ServiceInstaller(); 

     // The services run under the system account. 

     processInstaller.Account = ServiceAccount.LocalSystem; 

     // The services are started manually. 

     serviceInstaller1.StartType = ServiceStartMode.Manual; 
     serviceInstaller2.StartType = ServiceStartMode.Manual; 

     // ServiceName must equal those on ServiceBase derived classes. 

     serviceInstaller1.ServiceName = "Hello-World Service 1"; 

     // Add installers to collection. Order is not important. 

     Installers.Add(serviceInstaller1); 
     Installers.Add(processInstaller); 
    } 
} 

VS2008では、インストーラクラスをプロジェクトに簡単に追加できます。これは、新しいアイテムを追加するときにアイテムタイプとして表示されます。

+0

System.Configuration.Installと同様ですか? – Jeremy

+0

はい。私が投稿したこれらのリンクの両方は、そのコンテンツに「System.Configuration.Install」と表示されていました。 –

+0

申し訳ありませんが、コメントする前にリンクが表示されませんでした...コメントの削除について考えました。 – Jeremy

関連する問題