0

I want to create a windows service from a long running process. I'm able to create the service but I cannot execute it in any way.

I've also tries a very simple timeout.exe process with the same results.

> New-Service `
  -Name "test" `
  -BinaryPathName "C:\windows\system32\timeout.exe 30"

// output

Status   Name               DisplayName
------   ----               -----------
Stopped  test               test

After that, I'm trying to start service with

Start-Service test

And i receive IMMEDIATELY this output:

Start-Service: Service 'test (test)' cannot be started due to the following error: Cannot start service 'test' on computer '.'.

On event viewer are presente 2 event logs that are referencing a 30 seconds timeout that never happens: the system fails immediately.

enter image description here

What I am missing ?

1
  • 1
    A service is a special type of application that's been built to interface with the windows service control manager, if you register a regular desktop executable as a service its not going to work. You may like to try using svrany: learn.microsoft.com/en-us/troubleshoot/windows-client/… Commented Jun 24, 2022 at 13:29

1 Answer 1

1

I'm answering to my own question.

As @alex-k says a regular process cannot be started as service and must be special interface.

In this answer there are additional details https://stackoverflow.com/a/3582179/3120219

srvany.exe is a wrapper that implements the required interface and launch a process but can have some limitations.

Sign up to request clarification or add additional context in comments.

1 Comment

Instead of using srvany.exe you should create a new project in your solution and select windows service. Take a look at the generated base code. You can combine this code with your application (either console or UI) and register your app as service with a command line parameter. When the app is started without the parameter run your normal application. When started with the parameter go the service route. That way you'll get a hybrid app.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.