Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service stuck on "starting" status as local system account

Tags:

I developed a http server via console application in C# and decided to turn it into a Windows service to be able to initialize it without the need to login the machine.

I followed all the steps in How to create Windows Service and chose the account as "Local System", but when I install in my server machine and push the start button it takes a while and gives the following error:

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

After that, the service status stays stuck in "starting" and the application don't work and I can't even stop the service anymore.

Trying to work around this problem, I changed it to "Network Service", so it started normally, but the application was not listening in the port I set when I checked in the prompt with the command "netstat -an". But the application listens normally if i run it as a console application.

So I am looking for an answer to one of these two questions:

  1. What should I do to make the service starts properly with a Local System account?
  2. If I decide to use Network service account, what should I care about to guarantee that my service works properly as a server?
like image 745
joaocarlospf Avatar asked Jul 06 '15 14:07

joaocarlospf


People also ask

How do I force stop Wuauserv?

Press CTRL+ALT+DEL and click on Task Manager. Click on the Services tab. Find wuauserv and make note of the PID. Now open the Command Prompt or PowerShell as Admin and type in taskkill /f /pid **** where **** is your PID.


2 Answers

When I converted my console application to windows service I simply put my code directly in the OnStart method. However, I realized the OnStart method should start the service, but needs to end some time to the service indeed start. So I created a thread that runs my service and let the OnStart method finish. I tested and the service worked just fine. Here is how it was the code:

protected override void OnStart(string[] args) {     Listener(); // this method never returns } 

Here is how it worked:

protected override void OnStart(string[] args) {     Thread t = new Thread(new ThreadStart(Listener));     t.Start(); } 

But I still don't understand why the service ran (passed the "starting" status, but didn't work) when I used network service account. If anyone knows, I'll be glad to know the reason.

like image 195
joaocarlospf Avatar answered Oct 06 '22 00:10

joaocarlospf


If you have a service that is not responding or showing pending in Windows services that you are unable to stop, use the following directions to force the service to stop.

  • Start -> Run or Start -> type services.msc and press Enter
  • Look for the service and check the Properties and identify its service name
  • Once found, open a command prompt. Type sc queryex [servicename]
  • Identify the PID (process ID)
  • In the same command prompt type taskkill /pid [pid number] /f
like image 31
Salman Lone Avatar answered Oct 05 '22 23:10

Salman Lone