Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Writing a Win Service and a Command Line app in one



Permlink Replies: 2 - Last Post: Oct 10, 2016 10:55 PM Last Post By: Colin Maharaj
Colin Maharaj

Posts: 122
Registered: 12/2/99
Writing a Win Service and a Command Line app in one
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2016 2:05 PM
Is it possible to design a cmd line app that can also be a service.
Or,
Have a service that you can run at the command line with some switch.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Writing a Win Service and a Command Line app in one
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2016 10:37 AM   in response to: Colin Maharaj in response to: Colin Maharaj
Colin wrote:

Is it possible to design a cmd line app that can also be a service.

Yes. A service is nothing more than a standard Win32 app that makes calls
to the Service API when running as a service (RegisterServiceCtrlHandler/Ex(),
StartServiceCtrlDispatcher(), SetServiceStatus(), etc). So you can certain
have the app run in different modes depending on how it is started.

Have a service that you can run at the command line with some switch.

I would go the other way around. Make the app run as a console app by default,
and run as a service when started with a switch. Then you can include that
switch in the service's executable path when registering with the SCM.

--
Remy Lebeau (TeamB)
Colin Maharaj

Posts: 122
Registered: 12/2/99
Re: Writing a Win Service and a Command Line app in one
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 10, 2016 10:55 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Ah,
Very well, sounds promising....

On 10/10/2016 01:37 PM, Remy Lebeau (TeamB) wrote:

Colin wrote:

Is it possible to design a cmd line app that can also be a service.

Yes. A service is nothing more than a standard Win32 app that makes calls
to the Service API when running as a service (RegisterServiceCtrlHandler/Ex(),
StartServiceCtrlDispatcher(), SetServiceStatus(), etc). So you can certain
have the app run in different modes depending on how it is started.

Have a service that you can run at the command line with some switch.

I would go the other way around. Make the app run as a console app by default,
and run as a service when started with a switch. Then you can include that
switch in the service's executable path when registering with the SCM.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02