c# - 安装自研Windows Service

标签 c# windows-services

我正在尝试部署我编写的服务。这是安装日志文件:

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 的帐户设置为 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!");
    }
}

更新入口点:

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);
        }
    }
}

最佳答案

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

关于c# - 安装自研Windows Service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1580023/

相关文章:

windows-services - 有关 C# 中 Windows 服务的书籍和教程?

service - 我在 Windows 服务中收到 system.configuration.settingspropertynotfoundexception 错误

windows - 使用适用于服务运行的所有应用程序的 Windows 防火墙 API 创建规则

c# - 如何打开带附件的默认电子邮件客户端

c# - 处理项目时缓冲

javascript - .net core 2.0 signalr 为什么我不能使用用户名发送

c# - 配置系统初始化失败

c# - 在 c# 中作为 Windows 服务运行时,TCP/IP 套接字不从机器读取数据

c# - 在 Windows 服务中安装和运行 WCF 服务

c# - 在 C# 中,执行 "static"复制到 StringBuilder 对象的子字符串