简体   繁体   中英

Installing a self-developed Windows Service

I'm trying to deploy a service that I wrote. Here's the InstallLog file:

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.

As you can see, it's not working. I am not sure how to proceed, and have hit the wall with Bing and Google. I have set the Account to LocalSystem for the serviceProcessInstaller1. The code compiles fine, but now I would like to run the thing...any ideas? I am an administrator on my box, and I am running the command:

InstallUtil TweetLinkQueue.exe

from the VS2008 admin console.

UPDATED WITH /ShowCallStack option

Call Stack

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)

and here is the constructor:

public TweetLinkService()
{
    InitializeComponent();

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

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

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

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

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

I'm not sure what your specific problem is. It looks to me like the problem occurs while creating the EventLog source. Double-check that you've done that part correctly. You can reference the step-by-step here . EDIT: SPECIFICALLY LOOK AT STEP 9. The problem may be occuring because you're messing with the Application log instead of one specific to your application.

There's nothing wrong with using InstallUtil, but if you need to install your service on a foreign machine, InstallUtil is not guaranteed to be there. You can follow this step-by-step to make your Windows service executable install/uninstall itself without the need of InstallUtil. See here for those instructions.

To solve this issue right click on your Visual Studio 2008 Command Prompt and click run as administrator then you run your command like installutil C:\\mcWebService\\bin\\Debug\\mcWebService.exe then it will show you successful message. Hope this will solve your solution.

The LocalSystem account doesn't normally have permission to read the Security event log (or to create event sources for that matter).

The easiest and safest solution is to create an event source installation program that you can run under your own administration-level credentials on any machine for which you'll want to run this. It might be even worth trying this as a simple test, just to see if your account has the permission to do this.

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

If you execute that, does it succeed? You can check it by looking at the Application log's properties and browsing the Event sources on its Filter tab.

Alternately, since services have to be installed anyway, you could add an EventLogInstaller (which is misnamed - it's really an 'EventSourceInstaller' that will create EventLogs as needed) to the assembly instead of using EventLog.CreateEventSource in the service's constructor.

My issue was a window was popping to enter credentials and I was entering my username without the domain. Once I entered domain\\username all was fine.

I got the same unexplainable errors when installing windows services. In our case the user was the problem.

Installing the server with the administrator-user worked, but not for a local admin. This, however, is not a preferred solution, so we used this information to create a different user that could install the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM