Error 1053: the service did not respond to the sta

2019-01-10 07:03发布

I have recently inherited a couple of applications that run as windows services, and I am having problems providing a gui (accessible from a context menu in system tray) with both of them.

The reason why we need a gui for a windows service is in order to be able to re-configure the behaviour of the windows service(s) without resorting to stopping/re-starting.

My code works fine in debug mode, and I get the context menu come up, and everything behaves correctly etc.

When I install the service via "installutil" using a named account (i.e., not Local System Account), the service runs fine, but doesn't display the icon in the system tray (I know this is normal behavior because I don't have the "interact with desktop" option).

Here is the problem though - when I choose the "LocalSystemAccount" option, and check the "interact with desktop" option, the service takes AGES to start up for no obvious reason, and I just keep getting

Could not start the ... service on Local Computer.

Error 1053: the service did not respond to the start or control request in a timely fashion.

Incidentally, I increased the windows service timeout from the default 30 seconds to 2 minutes via a registry hack (see http://support.microsoft.com/kb/824344, search for TimeoutPeriod in section 3), however the service start up still times out.

My first question is - why might the "Local System Account" login takes SOOOOO MUCH LONGER than when the service logs in with the non-LocalSystemAccount, causing the windows service time-out? what's could the difference be between these two to cause such different behavior at start up?

Secondly - taking a step back, all I'm trying to achieve, is simply a windows service that provides a gui for configuration - I'd be quite happy to run using the non-Local System Account (with named user/pwd), if I could get the service to interact with the desktop (that is, have a context menu available from the system tray). Is this possible, and if so how?

Any pointers to the above questions would be appreciated!

30条回答
Melony?
2楼-- · 2019-01-10 07:26

Adding 127.0.0.1 crl.microsoft.com to the "Hosts" file solved our issue.

查看更多
\"骚年 ilove
3楼-- · 2019-01-10 07:27

After fighting this message for days, a friend told me that you MUST use the Release build. When I InstallUtil the Debug build, it gives this message. The Release build Starts fine.

查看更多
何必那么认真
4楼-- · 2019-01-10 07:28

To debug the startup of your service, add the following to the top of the OnStart() method of your service:

 while(!System.Diagnostics.Debugger.IsAttached) Thread.Sleep(100);

This will stall the service until you manually attach the Visual Studio Debugger using Debug -> Attach to Process...

Note: In general, if you need a user to interact with your service, it is better to split the GUI components into a separate Windows application that runs when the user logs in. You then use something like named pipes or some other form of IPC to establish communication between the GUI app and your service. This is in fact the only way that this is possible in Windows Vista.

查看更多
Bombasti
5楼-- · 2019-01-10 07:28

In my case the problem was missing version of .net framework.

My service used

<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

But .net Framework version of server was 4, so by changing 4.5 to 4 the problem fixed:

<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
查看更多
女痞
6楼-- · 2019-01-10 07:29

I was running into a similar problem with a Service I was writing. It worked fine then one day I started getting the timeout on Start errors. It happened in one &/or both Release and Debug depending on what was going on. I had instantiated an EventLogger from System.Diagnostics, but whatever error I was seeing must have been happening before the Logger was able to write...

If you are not aware of where to look up the EventLogs, in VS you can go to your machine under the Server Explorer. I started poking around in some of the other EventLogs besides those for my Service. Under Application - .NETRuntime I found the Error logs pertinent to the error on startup. Basically, there were some exceptions in my service's constructor (one turned out to be an exception in the EventLog instance setup - which explained why I could not see any logs in my Service EventLog). On a previous build apparently there had been other errors (which had caused me to make the changes leading to the error in the EventLog set up).

Long story short - the reason for the timeout may be due to various exceptions/errors, but using the Runtime EventLogs may just help you figure out what is going on (especially in the instances where one build works but another doesn't).

Hope this helps!

查看更多
一夜七次
7楼-- · 2019-01-10 07:30
  1. Build project in Release Mode.
  2. Copy all Release folder files to source path.
  3. Execute Window service using command prompt window in administrative access.
  4. Never delete files from source path.

At lease this works for me.

查看更多
登录 后发表回答