安装自行开发的Windows服务

时间:2009-10-16 19:39:49

标签: c# windows-services

我正在尝试部署我写的服务。这是InstallLog文件:

Installing assembly 'c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.exe'.
Affected parameters are:
   logtoconsole = 
   assemblypath = c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.exe
   logfile = c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.InstallLog
Installing service TweetLinkService...
Creating EventLog source TweetLinkService in log Application...
Rolling back assembly 'c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.exe'.
Affected parameters are:
   logtoconsole = 
   assemblypath = c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.exe
   logfile = c:\Users\brwatson\Development\Projects\TweetLinks\TweetLinkQueue\bin\Debug\TweetLinkQueue.InstallLog
Restoring event log to previous state for source TweetLinkService.
An exception occurred during the Rollback phase of the System.Diagnostics.EventLogInstaller installer.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
An exception occurred during the Rollback phase of the installation. This exception will be ignored and the rollback will continue. However, the machine might not fully revert to its initial state after the rollback is complete.

正如您所看到的,它不起作用。我不知道该如何继续,并且已经与Bing和Google发生冲突。我已经为ServiceProcessInstaller1设置了Account to LocalSystem。代码编译得很好,但现在我想运行这个东西......任何想法?我是我的盒子的管理员,我正在运行命令:

InstallUtil TweetLinkQueue.exe

来自VS2008管理控制台。

使用/ ShowCallStack选项更新

调用堆栈

An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all eve
nt logs could not be searched.  Inaccessible logs: Security.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String m
achineName, Boolean readOnly)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName
)
   at System.Diagnostics.EventLogInstaller.Install(IDictionary stateSaver)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.ServiceProcess.ServiceInstaller.Install(IDictionary stateSaver)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.AssemblyInstaller.Install(IDictionary savedSt
ate)
   at System.Configuration.Install.Installer.Install(IDictionary stateSaver)
   at System.Configuration.Install.TransactedInstaller.Install(IDictionary saved
State)

这是构造函数:

public TweetLinkService()
{
    InitializeComponent();

    if (!EventLog.SourceExists("TweetLinkQueue"))
    {
        EventLog.CreateEventSource("TweetLinkQueue", "Log");

        TweetLinksLog.Source = "TweetLinkQueue";
        TweetLinksLog.Log = "Log";

        TweetLinksLog.WriteEntry("Log Created!");
    }
}

使用ENtry Point更新:

namespace TweetLinkQueue
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new TweetLinkService() 
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

6 个答案:

答案 0 :(得分:116)

我遇到了这个问题,原因是我没有以管理员身份运行我的visual studio命令提示符。

答案 1 :(得分:13)

我不确定你的具体问题是什么。在我看来,在创建EventLog源时会出现问题。仔细检查您是否正确完成了该部分。您可以逐步引用here编辑:在第9步中明确查看。问题可能是因为您正在弄乱应用程序日志,而不是特定于您的应用程序的日志。

使用InstallUtil没有任何问题,但如果您需要在外部计算机上安装服务,则不保证InstallUtil在那里。您可以按照此步骤逐步使Windows服务可执行文件自行安装/卸载,而无需InstallUtil。有关这些说明,请参阅here

答案 2 :(得分:8)

要解决此问题,请右键单击Visual Studio 2008命令提示符,然后单击以管理员身份运行,然后运行命令,如installutil C:\ mcWebService \ bin \ Debug \ mcWebService.exe 然后它会告诉你成功的消息。 希望这能解决您的问题。

答案 3 :(得分:2)

LocalSystem帐户通常无权读取安全事件日志(或创建事件源)。

最简单,最安全的解决方案是创建一个事件源安装程序,您可以在您要运行它的任何计算机上使用您自己的管理级凭据运行该程序。它可能甚至值得尝试这个简单的测试,只是为了看看你的帐户是否有权这样做。

class Program {
    static void Main(string[] args) {
        EventLog.CreateEventSource("TestSource", "Application");
    }
}

如果你执行它,它会成功吗?您可以通过查看应用程序日志的属性并在其过滤器选项卡上浏览事件源来检查它。

或者,由于无论如何都必须安装服务,你可以添加一个EventLogInstaller(这是错误名称 - 它实际上是'EventSourceInstaller',它将根据需要创建EventLogs)而不是使用服务构造函数中的EventLog.CreateEventSource

答案 4 :(得分:0)

我的问题是弹出一个窗口输入凭据,而我输入的用户名没有域名。输入域名\用户名后,一切都很好。

答案 5 :(得分:0)

在安装Windows服务时出现了同样无法解释的错误。 在我们的案例中,用户就是问题所在。

以管理员用户身份安装服务器是可行的,但不适用于本地管理员。但是,这不是首选的解决方案,因此我们使用此信息来创建可以安装该服务的其他用户。

相关问题