Cannot start windows service from command line or debugger

Message: WINDOWS SERVICE START FAILURE

Whenever log in through user profile, a message is displayed as:

«Cannot start service from the command line or a debugger. A Windows Service must be installed (using installutil.exe) and then started with the Server Explorer, Windows Services, Administrative tool or the NET START command«

I am not aware of the reason but the observation afterwards are

  1. System slows down whether you work online or offline.
  2. Would not allow easily to shut down or restart the system through start menu and have to use the power button ultimately.

Request to suggest the solution if any.

Replies (1) 

Windows Services are the programs that operates in the background which makes the Windows system whole. To resolve this issue, we suggest running a System File Checker scan and Deployment Image Servicing and Management comand-line utility. Here are the steps:

  1. Open the Start menu, type ‘cmd’, right-click on Command Prompt and select
  2. Enter the following command-line (press enter after each command-line):

DISM /Online /Cleanup-Image /CheckHealth
DISM /Online /Cleanup-Image /ScanHealth
DISM /Online /Cleanup-Image /RestoreHealth
sfc /scannow

Should the issue persists, please make sure that all available Windows updates are installed.

Cannot start windows service from command line or debugger

This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.

Answered by:

Question

Answers

Do you mean you cannot start service from the command line?

Like following cmd,

Using net stop [service name] to stop it and net start [service name] to start it up again basically restarting the service.

If so, you should make sure you have done the thing correctly. If tha’t not what you want, please be more specific about what you are trying to do and feel free to let me know.

Firstly you should make sure your service code is working fine.

Secondly, if you are win7 or win8 os,

  1. On the Windows Start menu or Start screen, choose Visual Studio , Visual Studio Tools , Developer Command Prompt .
  2. A Visual Studio command prompt appears.
  3. Run InstallUtil.exe from the command prompt with your project’s output as a parameter:

Here is my screenshot,

Читайте также:  Что удалить при сборке windows

We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.

Cannot start windows service from command line or debugger

Answered by:

Question

I’m getting an error message like «Cannot start service from the command line or a debugger. A windows service must frist be be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.» when I started debugging my service from VS 2008 Professional Edition. Following is how I using my ‘OnStart(. )’ method:

private bool IsStarted = true;
private NotificationProcessBusiness notificationProcess = null; // Initializes in CTOR

protected override void OnStart(string[] args)
<
if (IsStarted)
<
notificationProcess.StartNotificationProcess();
IsStarted = false;
>
>

I am not sure why this error is occuring. I googled all sites but no idea about the solution.

Please can some one help me in resolving this problem.

Answers

I’m not sure you can debug a service the way you would a normal application.

The way we normally do it is;

1. Install the service.

2. Make sure the service is ‘stopped’ before building the project, use net stop ‘servicename’ or service control manager in control panel -> administrative tools -> services to stop the service.

3. Build the code.

4. Start the service, either with net start ‘servicename’ or again with the service control manager.

5. In VS go to the debug menu and choose ‘Attach to process’ and choose the service process from the list of running processes.

In order to enable debugging the service startup code, we usually have something like

#if DEBUG
System.Threading.Thread.Sleep(15000);
#end if

in the top of our on start method, which means in debug builds (not release ones) the service will wait 15 seconds when it starts which is normally long enough to bring up the attach to process dialog and select the service process.

All replies

Have you installed your service? To install you service, assuming Service1.exe is the exe you get after building your project, run InstallUtil Service1.exe from VS command prompt. This will install your service and then you need to start the service in services.mmc.

I’m not sure you can debug a service the way you would a normal application.

Читайте также:  Пинг большими пакетами windows

The way we normally do it is;

1. Install the service.

2. Make sure the service is ‘stopped’ before building the project, use net stop ‘servicename’ or service control manager in control panel -> administrative tools -> services to stop the service.

3. Build the code.

4. Start the service, either with net start ‘servicename’ or again with the service control manager.

5. In VS go to the debug menu and choose ‘Attach to process’ and choose the service process from the list of running processes.

In order to enable debugging the service startup code, we usually have something like

#if DEBUG
System.Threading.Thread.Sleep(15000);
#end if

in the top of our on start method, which means in debug builds (not release ones) the service will wait 15 seconds when it starts which is normally long enough to bring up the attach to process dialog and select the service process.

Was your service built in debug mode with debug symbols ? Is the .pdb file in the same folder as the exe is installed ? Do you have a break-point set in your service code ?

If you have a pdb file and the date and time is rougly the same as the exe, then the debug symbols were rebuilt when you compiled and so that’s not the problem.

When you are connected to the process do the breakpoints show as filled red circles, or the outline of a red circle ? Are your break points in the right place ? It might be that your break points just aren’t being hit ?

When i attach it to the process it doesn’t work at all, it does nothing, and if i don’t attach it to the process it does work until it hits System.ServiceProcess.ServiceBase.Run(ServicesToRun) then i get this message:

Cannot start service from the command line or a debugger. A windows service must first be installed (using installutil.exe) and then started with the ServerExplorer, Services Admin Tool or the Net Start command

even though i installed the service with the installutil

Shared Sub Main()
Dim sArgs As String()
sArgs = System.Environment.GetCommandLineArgs()
If sArgs.Length > 1 Then
If sArgs(1).ToLower() = «console» Then
Dim oService As New MotoStoreUpdate()
oService.OnStart(sArgs)
End If
End If
Dim ServicesToRun As System.ServiceProcess.ServiceBase()
ServicesToRun = New System.ServiceProcess.ServiceBase()
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub

That’s correct, you can’t debug a service that way, you must use the attach to process method.

Can you please answer the question about the breakpoints, i.e connect to the running service, then check the breakpoint symbol in the IDE and tell us what kind it is.

Читайте также:  Отключение брандмауэра windows как службу тип запуска поставить отключена

at first the breakpoints start as an outline while it loads the symbols but after that they’re filled red circles and it does nothing, the thing is tha when i debug it without attaching it to a process it goes through all the breakpoints until it hits

that’s where it stops i get the message and stops.

Hmm, ok, so it’s defintely not a problem with loading the symbols then.

Where are your break points ? Do you have a break point in the OnStart method ?

as the *very* first line in the onstart method, recompile/update the installed exe, then start it and attach to it with VS with a break point set on the first line after the sleep command above.

It’s possible the service is starting and executing your start-up code before VS is connected, and then it is not doing anything (waiting on a timer, run out of work, or something. hard to know without seeing the code itself). By putting in the delay you ensure that you get 1 minute to attach VS before you code actually executes.

still not working, here’s the code for the service, the UpdateBase class is the one that does all the update of the store

Public Class StoreUpdate

Private update As UpdateBase = New UpdateBase()

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Shared Sub Main()
Dim sArgs As String()
sArgs = System.Environment.GetCommandLineArgs()
If sArgs.Length > 1 Then
If sArgs(1).ToLower() = «console» Then
Dim oService As New MotoStoreUpdate()
oService.OnStart(sArgs)
End If
End If

Dim ServicesToRun As System.ServiceProcess.ServiceBase()
ServicesToRun = New System.ServiceProcess.ServiceBase()
System.ServiceProcess.ServiceBase.Run(ServicesToRun)

Protected Overrides Sub OnStart(ByVal args() As String)
System.Threading.Thread.Sleep(60000)
update.Start()
End Sub

Protected Overrides Sub OnStop()
update.Abort()
End Sub

Protected Overrides Sub OnShutdown()
update.Abort()
End Sub

i also call the service in another project and it does work fine, i use it the first time the application runs so it updates all the content, it works fine it calls the service and starts it and does everything it has to do, here’s the code for that

Public Sub ServStart()
Try
Dim srvController As New ServiceProcess.ServiceController(«StoreUpdate»)
If Not srvController.Status = ServiceProcess.ServiceControllerStatus.Running Then
srvController.Start()
End If

Catch ex As Exception
Dim oErr As New cError(ex, «Error: Servicio ‘StoreUpdate’ no instalado.»)
End Try
End Sub

Оцените статью