简体   繁体   中英

Error installing Windows service — The service did not respond to the start or control request in a timely fashion

I have a Windows service application which I have installed on my machine without issue. I went to install it on another machine, and I'm receiving the error

Error 1001. An exception occurred during the Commit phase of the installation. This exception will be ignored and installation will continue. However, the application might not function correctly after installation is complete. Cannot start service MyService on computer '.'. The service did not respond to the start or control request in a timely fashion.

This error is popping up immediately without any hanging. Normally I would only expect to see this error after a hang.

I'm using the .NET 4 framework, which is installed on both machines. I've tried disabling the antivirus program thinking that might be interfering with the service startup, but that yielded the same error. The firewall was also disabled.

Is there anything else that could be causing this issue?

This behaviour usually occurs when an exception is thrown in the WinService's OnStart method and is not caught in a try-catch block. I believe you can check out the exception message and stack trace using the EventViewer, if not you can easily implement a simple logging functionality using the EventLog class .

Sometimes the exception is thrown because the service is not running under a privileged account. To fix this you have to configure your installer's ServiceProcessInstaller object like the following:

myServiceInstaller.Account = ServiceAccount.User;
myServiceInstaller.Username = "Domain name\User name";
myServiceInstaller.Password = "qwerty";

Thanks for your help everyone. I realized the issue was due to the .NET Framework installed on the two different machines. My machine had .NET Framework 4 Client Profile and .NET Framework 4 Extended, and the other machine only had .NET Framework 4 Client Profile. Evidently for some of the components in the service need libraries that aren't present in the .NET Framework 4 Client Profile.

Since your service runs on another computer, and assuming the code is the same for both, the issue may be something having to do with permissions. Ensure the account your service is running under has sufficient permissions to any folders where it writes files. If you write to the Event Log, ensure the service' account has the necessary permissions for that.

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