そのため、ここでもまた別の MSDN の失敗が発生しています。いつものように、C# で Windows サービスを作成する方法を学ぶことにしました。多くのチュートリアルでは不完全または不十分なコードしか提供されていなかったため、MSDN を使用することにしました。
すべての手順に従いましたが、サービスがインストールされません。
私がフォローしているページは次のとおりです。http://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
私のコードは次のとおりです。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace WindowsService1
{
public partial class WindowsService1 : ServiceBase
{
public WindowsService1()
{
InitializeComponent();
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource", "MyNewLog");
}
eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
}
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
}
protected override void OnStop()
{
eventLog1.WriteEntry("In onStop.");
}
protected override void OnContinue()
{
eventLog1.WriteEntry("In OnContinue.");
}
}
}
開発者コマンド プロンプトに入り、.exe を含むディレクトリ (デバッグ フォルダー) に移動しました。
installutil WindowsService1.exe
また、試してみinstallutil.exe WindowsService1.exe
ましたが、インストールは常に失敗し、次のテキストが表示されます。
C:\Program Files (x86)\Microsoft Visual Studio 11.0>cd C:\Users\Tommy\Documents\ Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>installutil WindowsService1.exe Microsoft (R) .NET Framework インストール ユーティリティ バージョン 4.0.30319.32559 Copyright (C) Microsoft Corporation. 全著作権所有。
トランザクション インストールの実行。
インストールのインストール フェーズの開始。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況のログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。アセンブリ 'C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Windows sService1\WindowsService1\bin\Debug\WindowsService1.exe' をインストールしています。影響を受けるパラメーターは次のとおりです。 Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.
インストール フェーズ中に例外が発生しました。System.InvalidOperationException: コンピューター r '.' でサービス コントロール マネージャーを開けません。この操作には、他の権限が必要になる場合があります。内部例外 System.ComponentModel.Win32Exception がスローされ、次のエラー メッセージが表示されました: アクセスが拒否されました。
インストールのロールバック フェーズが開始されます。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況のログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。アセンブリ 'C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.exe' をロールバックしています。影響を受けるパラメーターは次のとおりです。 logtoconsole = logfile = C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService 1\WindowsService1\bin\Debug\WindowsService1.InstallLog assemblypath = C:
ロールバック フェーズが正常に完了しました。
トランザクションのインストールが完了しました。インストールに失敗し、ロールバックが実行されました。
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>installutil WindowsService1 Microsoft (R) .NET Framework インストール ユーティリティ バージョン 4.0.30319.32559 Copyright (C) Microsoft Corporation. 全著作権所有。
インストールの初期化中に例外が発生しました: System.IO.FileNotFoundException: ファイルまたはアセンブリを読み込めませんでした 'file:///C:\Use rs\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\b in\Debug\ WindowsService1' またはその依存関係の 1 つ。システムは、指定されたファイルを見つけることができません..
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>installutil WindowsService1.exe Microsoft (R) .NET Framework インストール ユーティリティ バージョン 4.0.30319.32559 Copyright (C) Microsoft Corporation. 全著作権所有。
トランザクション インストールの実行。
インストールのインストール フェーズの開始。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況のログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。アセンブリ 'C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Windows sService1\WindowsService1\bin\Debug\WindowsService1.exe' をインストールしています。影響を受けるパラメーターは次のとおりです。 Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.
インストール フェーズ中に例外が発生しました。System.InvalidOperationException: コンピューター r '.' でサービス コントロール マネージャーを開けません。この操作には、他の権限が必要になる場合があります。内部例外 System.ComponentModel.Win32Exception がスローされ、次のエラー メッセージが表示されました: アクセスが拒否されました。
インストールのロールバック フェーズが開始されます。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況のログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。アセンブリ 'C:\Users\Tommy\Documents\Visual Studio 2013\Projects\Wind owsService1\WindowsService1\bin\Debug\WindowsService1.exe' をロールバックしています。影響を受けるパラメーターは次のとおりです。 logtoconsole = logfile = C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService 1\WindowsService1\bin\Debug\WindowsService1.InstallLog assemblypath = C:
ロールバック フェーズが正常に完了しました。
トランザクションのインストールが完了しました。インストールに失敗し、ロールバックが実行されました。
C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug>
また、INSTALLLOG ファイルを Debug ディレクトリに出力します。これには (同じ情報が含まれます):
トランザクション インストールの実行。
インストールのインストール フェーズの開始。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況については、ログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。
インストール フェーズ中に例外が発生しました。System.InvalidOperationException: コンピューター '.' でサービス コントロール マネージャーを開けません。この操作には、他の権限が必要になる場合があります。内部例外 System.ComponentModel.Win32Exception がスローされ、次のエラー メッセージが表示されました: アクセスが拒否されました。
インストールのロールバック フェーズが開始されます。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況については、ログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。
ロールバック フェーズが正常に完了しました。
トランザクションのインストールが完了しました。
トランザクション インストールの実行。
インストールのインストール フェーズの開始。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況については、ログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。
インストール フェーズ中に例外が発生しました。System.InvalidOperationException: コンピューター '.' でサービス コントロール マネージャーを開けません。この操作には、他の権限が必要になる場合があります。内部例外 System.ComponentModel.Win32Exception がスローされ、次のエラー メッセージが表示されました: アクセスが拒否されました。
インストールのロールバック フェーズが開始されます。C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.exe アセンブリの進行状況については、ログ ファイルの内容を参照してください。このファイルは、C:\Users\Tommy\Documents\Visual Studio 2013\Projects\WindowsService1\WindowsService1\bin\Debug\WindowsService1.InstallLog にあります。
ロールバック フェーズが正常に完了しました。
トランザクションのインストールが完了しました。
それでは、MSDN に戻ります。インストールが失敗した場合の対処方法を確認するには、代わりに次のように表示されます。
If the service installs successfully, installutil.exe will report success.
インストールが失敗した場合の対処方法に関する情報は他にありません。
私はこれに何日も費やし、8 つ以上のチュートリアルに従いましたが、そのすべてが不完全または悪いコード (動作しません) です。それで、私は最終的に MSDN を再び信頼することにしましたが、いつものように、いったい何が起こっているのか疑問に思っています。
私のユーザー アカウントには完全な読み取り/書き込み/実行権限があり、管理者です。[コンピューターの管理] (> [サービスとアプリケーション]) を確認し、Windows サービスがそこに表示されていないことを確認しました。
私は今何をしますか?(動作する) Windows サービスを作成するにはどうすればよいですか?