Phillip Schmidt
Phillip Schmidt

Reputation: 8818

Starting a Windows Service programmatically

I have a quartz.NET project set up which should schedule a windows service to run every so often. Currently, I am trying to start the service like this:

Process.Start("path/app.exe");

But I'm getting: "Cannot start a service from the command line or a debugger. A Windows Service must first be installed and then started with the ServerExplorer, Windows Services Admin tool, or the NET START command.

So I'm wondering, first of all, will this go away in release mode? Or am I going to have to find another way to go about this. Either way, I need to be able to schedule this job programmatically.

Upvotes: 0

Views: 1074

Answers (1)

usr
usr

Reputation: 171178

The message tells you a few ways how to start the service, but those are not the right way to do it from C#. There is a better way: Use the System.ServiceProcess.ServiceController class to start the service.

Upvotes: 3

Related Questions