編集:私はこの質問に報奨金を始めています。今のところ、VS2010 Pro Betaを使用してアプリケーションを開発していますが、通常は.netショップではないため、エクスプレスエディションでビルドできるようにしたいと考えています。 2人の開発者がVSPROを使用しており、チーム全体で利用できるわけではありません。
受け入れられた回答であり、賞金を請求するには、vb 2008ExpressEditionを使用してWindowsサービスをインストールおよびアンインストールできるようにするサンプルコードと手順を提供する必要があります。必ずしも私のコードから始める必要はありません(ただし、その要点は以下に含まれています)。
サービスとして実行したいVB.NETアプリケーションを作成しました。現在、「Service」テンプレートに付属していないVB.net Express Edition(2008)を使用していますが、Serviceクラス(ServiceBaseから継承)とInstallerクラス(Installerから継承)を追加しました。どちらの場合も、MSDNのサンプルコードに従っています。残念ながら、このコードをインストールしてサービスとして実行することはできませんでした。
このコードの要点は、sampleListenerと呼ばれるTCPリスナークラスです。sampleListenerクラスをスタートアップオブジェクトとして設定してプロジェクトを実行すると、コンソールアプリケーションとして正常に実行されます。
sampleListenerを起動するだけのサービスクラス(以下)があります。
Public Class sampleSocketService
Inherits System.ServiceProcess.ServiceBase
Public Sub New()
Me.ServiceName = "sample Socket Service"
Me.CanStop = True
Me.CanPauseAndContinue = True
Me.AutoLog = True
End Sub
Shared Sub Main()
System.ServiceProcess.ServiceBase.Run(New sampleSocketService)
End Sub
Protected Overrides Sub OnStart(ByVal args() As String)
sampleListener.Main()
End Sub
End Class
私の問題の原因だと思うインストーラークラスもあります。これが私が最初に書いたインストーラークラスです。
Imports System
Imports System.Collections
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.ComponentModel
<RunInstallerAttribute(True)> _
Public Class sampleSocketServiceInstaller
Inherits Installer
Private serviceInstaller1 As ServiceInstaller
Private processInstaller As ServiceProcessInstaller
Public Sub New()
' Instantiate installers for process and services.
processInstaller = New ServiceProcessInstaller()
serviceInstaller1 = New ServiceInstaller()
processInstaller.Account = ServiceAccount.LocalSystem
serviceInstaller1.StartType = ServiceStartMode.Automatic
' ServiceName must equal those on ServiceBase derived classes.
serviceInstaller1.ServiceName = "sample Socket Service"
' Add installers to collection. Order is not important.
Installers.Add(serviceInstaller1)
Installers.Add(processInstaller)
End Sub
End Class
これでinstallutil.exeを実行すると、次のメッセージが生成されます。
An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
これはセキュリティの問題のように見えますが、管理者として実行を使用して開いたcmdウィンドウで実行しています。
オンラインの例に基づいて、はるかに単純化されたインストーラークラスを試しました。
Imports System.ComponentModel
Imports System.Configuration.Install
<RunInstaller(True)> Public Class ProjectInstaller
Inherits System.Configuration.Install.Installer
End Class
これはとてつもなく単純なようで、どのように機能するのか理解できませんでしたが、実際には機能しませんでした。ただし、このバージョンのインストーラークラスを使用してプロジェクトでinstallutil.exeを実行すると、installutil.exeはエラーメッセージをスローせず、サービスが正常にインストールされたことを報告します。
インストーラークラスに、最初の例の一部を実行するコードが必要だと思いますが、エラーの原因となっている部分は実行しません。
助言がありますか?
(これは、明確にするため、および元々含まれていなかったコード例を追加するために大幅に編集されています)