安装自行开发的Windows服务

Bra*_*son 35 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.
Run Code Online (Sandbox Code Playgroud)

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

InstallUtil TweetLinkQueue.exe

来自VS2008管理控制台.

UPDATED with/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)
Run Code Online (Sandbox Code Playgroud)

这是构造函数:

public TweetLinkService()
{
    InitializeComponent();

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

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

        TweetLinksLog.WriteEntry("Log Created!");
    }
}
Run Code Online (Sandbox Code Playgroud)

使用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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 118

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

  • 我创建了一个用于安装服务的BAT文件,我以管理员身份运行BAT文件(右键单击BAT文件并单击"以管理员身份运行"选项)但它无法正常工作.为了使其工作,我"以管理员身份运行"命令行提示符(cmd.exe)而不是BAT文件.然后,我手动安装它,它工作. (2认同)

Mat*_*vis 14

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

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


小智 8

为了解决这个问题,用鼠标右键单击您的Visual Studio 2008的命令提示符,然后单击以管理员身份运行,那么你喜欢installutil运行C您的命令:\ mcWebService\BIN \调试\ mcWebService.exe然后它会告诉你成功的消息.希望这将解决您的解决方案.