473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hybrid Windows Service + Console App

For some reason the question, "Can I make an EXE that is both a Windows
Service and a Console Application?" has come up quite a bit for me over the
last few weeks.

I've been doing this for years, but for some reason I've never seen it
documented anywhere. C# (or VB.Net) is perfectly happy to create an EXE that
can be:
1 - Both a WinForms App or a Windows Service
2 - Both a Console App or a Windows Service

(or, indeed, any combination of the three).

This is typically useful for debugging - it's nice to have a single .EXE
that you can run from the command line (with "-debug"), or start as a
Windows Service. The classic trick of "push the code into a Class and create
two Exe's" always struck me as a bit silly.

I added this, along with the relevant C# souce code, to a blog entry at:
http://www.coversant.com/dotnetnuke/...=88&EntryID=19
--
Chris Mullins MCSD.Net, MCPD Enterprise
http://www.coversant.net/blogs/cmullins

Sep 28 '06 #1
2 2605
There must be a better way of detecting how an EXE has been invoked rather
than looking at command line arguments.

--
Barny
"Chris Mullins" wrote:
For some reason the question, "Can I make an EXE that is both a Windows
Service and a Console Application?" has come up quite a bit for me over the
last few weeks.

I've been doing this for years, but for some reason I've never seen it
documented anywhere. C# (or VB.Net) is perfectly happy to create an EXE that
can be:
1 - Both a WinForms App or a Windows Service
2 - Both a Console App or a Windows Service

(or, indeed, any combination of the three).

This is typically useful for debugging - it's nice to have a single .EXE
that you can run from the command line (with "-debug"), or start as a
Windows Service. The classic trick of "push the code into a Class and create
two Exe's" always struck me as a bit silly.

I added this, along with the relevant C# souce code, to a blog entry at:
http://www.coversant.com/dotnetnuke/...=88&EntryID=19
--
Chris Mullins MCSD.Net, MCPD Enterprise
http://www.coversant.net/blogs/cmullins

Sep 28 '06 #2
I constantly need to write windows services that run with no user logged in,
and then display a console interface IF someone does log in...
The way i've always done it is to write 2 executables. One is the service,
one is the interface.

When user logs in, the interface displays what is happening with the
service, and gives the user control.
When they log out, the service continues to do its job.

There must be a better way.

"Barny" <Ba***@discussions.microsoft.comwrote in message
news:30**********************************@microsof t.com...
There must be a better way of detecting how an EXE has been invoked rather
than looking at command line arguments.

--
Barny
"Chris Mullins" wrote:
>For some reason the question, "Can I make an EXE that is both a Windows
Service and a Console Application?" has come up quite a bit for me over
the
last few weeks.

I've been doing this for years, but for some reason I've never seen it
documented anywhere. C# (or VB.Net) is perfectly happy to create an EXE
that
can be:
1 - Both a WinForms App or a Windows Service
2 - Both a Console App or a Windows Service

(or, indeed, any combination of the three).

This is typically useful for debugging - it's nice to have a single .EXE
that you can run from the command line (with "-debug"), or start as a
Windows Service. The classic trick of "push the code into a Class and
create
two Exe's" always struck me as a bit silly.

I added this, along with the relevant C# souce code, to a blog entry at:
http://www.coversant.com/dotnetnuke/...=88&EntryID=19
--
Chris Mullins MCSD.Net, MCPD Enterprise
http://www.coversant.net/blogs/cmullins


Sep 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message...
9
by: Hardy Wang | last post by:
Hi all: I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based ont the code...
7
by: Mike | last post by:
I want to create a windows service that will monitor another window service. what i need for the service to do is, if a service is stopped I need it to start the service back up example: ...
6
by: Mark Allison | last post by:
Hi, I have an application that I want to be to run in Console mode and GUI mode. If no params are entered, I want the GUI fired up, if params are entered, then go into console mode. I believe...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
1
by: Samuel R. Neff | last post by:
We're using a 3rd party C DLL in a project that we don't have source for. When we call the DLL from a console app everything works fine. However, when we call it from a Windows Service, the DLL...
12
by: Noam | last post by:
I had originally written a program as a c# console application. The program used a reference that I wrote in c++. Later I was told to re-write the application as a windows service. When the service...
0
by: Chris Mullins | last post by:
For some reason the question, "Can I make an EXE that is both a Windows Service and a Console Application?" has come up quite a bit for me over the last few weeks. I've been doing this for...
7
by: sunil | last post by:
Hi all, I read an article from http://www.c-sharpcorner.com/Code/2003/Sept/InstallingWinServiceProgrammatically.asp about how to install a windows service programmatically. Based on the code...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.