473,670 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting Windows C# Application to a Windows NT Service

Hey guys,

I've written a fairly simple Windows C# Application using Visual Studio
2005. I have to manually run it, but I would prefer to have it run on it's
own, as if it was a Windows NT Service. I am a Delphi convert (still use it
for some jobs). When developing in Delphi, I would write a console
application that would basically run on it's own. In order for me to register
it as a Windows NT Service, I seem to recall that I would do something like
SVCREG32.EXE (Application.EX E) /REGISTER or something to that effect. It
would then appear under my list of Services. I could control the startup of
the application.

In my Delphi application itself, I would use a timer which would make the
app run once every... I dunno 2 minutes or something?

With C#, I don't have that. I haven't actually checked to see if there is a
timer component, but I'm sure I can do something. My real question is though,
how can I register my Windows C# Console Application as a Windows NT Service?
Does anyone have any examples of how to accomplish this?
Thanks!
Oct 4 '06 #1
8 6766
Todd Jaspers <To*********@di scussions.micro soft.comwrote:
>
With C#, I don't have that. I haven't actually checked to see if there is a
timer component, but I'm sure I can do something. My real question is though,
how can I register my Windows C# Console Application as a Windows NT Service?
Does anyone have any examples of how to accomplish this?
I don't think that you really want a service to be just any old console app.
Take a look at this link for reference.

http://msdn2.microsoft.com/en-us/library/y817hyb6.aspx

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Oct 4 '06 #2
Hello Todd,

Creating services with UI isn't a good approach due to security reasons,
because your service works in different context ragher then user and service
may start even when no user logged on

Just create service apps like Thomas recomended u

TJHey guys,
TJ>
TJI've written a fairly simple Windows C# Application using
TJVisual Studio 2005. I have to manually run it, but I would prefer to
TJhave it run on it's own, as if it was a Windows NT Service. I am a
TJDelphi convert (still use it for some jobs). When developing in
TJDelphi, I would write a console application that would basically run
TJon it's own. In order for me to register it as a Windows NT Service,
TJI seem to recall that I would do something like SVCREG32.EXE
TJ(Application. EXE) /REGISTER or something to that effect. It would
TJthen appear under my list of Services. I could control the startup
TJof the application.
TJ>
TJIn my Delphi application itself, I would use a timer which would
TJmake the app run once every... I dunno 2 minutes or something?
TJ>
TJWith C#, I don't have that. I haven't actually checked to see if
TJthere is a timer component, but I'm sure I can do something. My real
TJquestion is though, how can I register my Windows C# Console
TJApplication as a Windows NT Service? Does anyone have any examples
TJof how to accomplish this?
TJ>
TJThanks!
TJ>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Oct 4 '06 #3


"Michael Nemtsev" wrote:
Hello Todd,

Creating services with UI isn't a good approach due to security reasons,
because your service works in different context ragher then user and service
may start even when no user logged on

Just create service apps like Thomas recomended u

Thanks Guys... Ill take a look at the link. I think I might not have made
myself very clear, but there would be no UI in this application. Although
it's just a windows app now, I would convert it to a console app with no UI
interface at all. I would actually want it to run on startup even if no user
logged in. It would be pulling data from one SQL database and transmitting
data through an SDK.
Thanks!
Oct 4 '06 #4
Oh ok!!!

I just read the link... I'm still new to VS 2005 (or VS in general) so I
completely missed the fact that there is a TYPE of project I can create from
scratch that's already meant as a service.

I'll just create a new app and copy my code from my console app into it.
Thanks guys!

Oct 4 '06 #5
Using a CLI app with a timer is not a service. You can't start / stop /
pause it etc.

Dot Net has very powerful abilities to build services. You start them,
stop, pause have them auto start, etc. It is very easy to do.
You do write them like a console app, but you start them differently.

You need a servicebase - look it up in MSDN and it gives a pretty good
example including how to write the Install class correctly.
"Todd Jaspers" <To*********@di scussions.micro soft.comwrote in message
news:BB******** *************** ***********@mic rosoft.com...
>

"Michael Nemtsev" wrote:
>Hello Todd,

Creating services with UI isn't a good approach due to security reasons,
because your service works in different context ragher then user and
service
may start even when no user logged on

Just create service apps like Thomas recomended u


Thanks Guys... Ill take a look at the link. I think I might not have made
myself very clear, but there would be no UI in this application. Although
it's just a windows app now, I would convert it to a console app with no
UI
interface at all. I would actually want it to run on startup even if no
user
logged in. It would be pulling data from one SQL database and transmitting
data through an SDK.
Thanks!

Oct 4 '06 #6
Something else you might want to consider: separating your business logic
from your interface logic. That is, create a business class that performs
the actual work, but only presents a programming interface. Then you can
host it in any kind of service or UI that you want in the future.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

If the Truth hurts, wear it.

"Todd Jaspers" <To*********@di scussions.micro soft.comwrote in message
news:48******** *************** ***********@mic rosoft.com...
Oh ok!!!

I just read the link... I'm still new to VS 2005 (or VS in general) so I
completely missed the fact that there is a TYPE of project I can create
from
scratch that's already meant as a service.

I'll just create a new app and copy my code from my console app into it.
Thanks guys!

Oct 4 '06 #7
Shoot... I have VS 2005 Standard... everywhere I look it says the Service
components aren't supported because I don't have Professional or higher... :(

Do I have any other option other than to ask my Boss to buy the Professional
version?
Thanks!

Todd

"EmeraldShi eld" wrote:
Using a CLI app with a timer is not a service. You can't start / stop /
pause it etc.

Dot Net has very powerful abilities to build services. You start them,
stop, pause have them auto start, etc. It is very easy to do.
You do write them like a console app, but you start them differently.

You need a servicebase - look it up in MSDN and it gives a pretty good
example including how to write the Install class correctly.
"Todd Jaspers" <To*********@di scussions.micro soft.comwrote in message
news:BB******** *************** ***********@mic rosoft.com...


"Michael Nemtsev" wrote:
Hello Todd,

Creating services with UI isn't a good approach due to security reasons,
because your service works in different context ragher then user and
service
may start even when no user logged on

Just create service apps like Thomas recomended u

Thanks Guys... Ill take a look at the link. I think I might not have made
myself very clear, but there would be no UI in this application. Although
it's just a windows app now, I would convert it to a console app with no
UI
interface at all. I would actually want it to run on startup even if no
user
logged in. It would be pulling data from one SQL database and transmitting
data through an SDK.
Thanks!


Oct 4 '06 #8
Todd,

I am using VS2005 team Suite that has a 180 day trial. Maybe if you
impress your boss after 180 days he may pay for it. :)

I have done exactly what you are asking about. I too am from delphi and
just wrote 6 services.

Like someone said above, keep the business logic seperate. I have both
a GUI interface and a service. They both call a shared unit.

basically, I create 2 projects and put them in the same root. Then I
create a common directory. You would then add the shared unit. Make
sure when you add that you click the little down arrow key on the add
dialog and chose to add a link. That way you don't have two different
copies. Why MS made that arrow so small an unobvious is beyond me.

This way I can test and watch debug info to the screen on the GUI app
and then launch it as a service when I am satisfied.

Hint, use system timers not windows form timers.

Any questions feel free to ask. I have learned a lot in the last 45
days. No doubt, there is always a better way but i will keep learning.

-Markus_R
Todd Jaspers wrote:
Shoot... I have VS 2005 Standard... everywhere I look it says the Service
components aren't supported because I don't have Professional or higher... :(

Do I have any other option other than to ask my Boss to buy the Professional
version?
Thanks!

Todd

"EmeraldShi eld" wrote:
Using a CLI app with a timer is not a service. You can't start / stop /
pause it etc.

Dot Net has very powerful abilities to build services. You start them,
stop, pause have them auto start, etc. It is very easy to do.
You do write them like a console app, but you start them differently.

You need a servicebase - look it up in MSDN and it gives a pretty good
example including how to write the Install class correctly.
"Todd Jaspers" <To*********@di scussions.micro soft.comwrote in message
news:BB******** *************** ***********@mic rosoft.com...
>
>
"Michael Nemtsev" wrote:
>
>Hello Todd,
>>
>Creating services with UI isn't a good approach due to security reasons,
>because your service works in different context ragher then user and
>service
>may start even when no user logged on
>>
>Just create service apps like Thomas recomended u
>
>
Thanks Guys... Ill take a look at the link. I think I might not have made
myself very clear, but there would be no UI in this application. Although
it's just a windows app now, I would convert it to a console app with no
UI
interface at all. I would actually want it to run on startup even if no
user
logged in. It would be pulling data from one SQL database and transmitting
data through an SDK.
>
>
Thanks!
Oct 4 '06 #9

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

Similar topics

9
7252
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 stopping. Please advise how to stop the service. Thanks, SP
5
2514
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant applications. I am testing an upgrade of all of the sites and have converted the main root site...although not necessarily fixed any issues. I move on instead and converted one of the virtual roots that is a seperate
3
1484
by: Derek Martin | last post by:
Hi there, kind of a dumb question, but it falls in line with not understanding (go figure) every nuance about .Net. Is it relatively straight forward to convert a VB.Net built app to an ASP.Net web system? If I am not just way off in left field, it would seem to be not too difficult, but am curious if anybody had experience doing or attempting this. Thanks, Derek
2
2278
by: Dave | last post by:
Hi. I have an application that uses sockets, as per below: m_clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); int iPortNo =8000; IPEndPoint ipEnd = new IPEndPoint (ip,iPortNo); m_clientSocket.Connect ( ipEnd ); It works fine, however when I close my application, the application does not receive any more data via the sockets and the application that sends it the
2
4499
by: asadikhan | last post by:
I have written a console application that clears out some folders. I want this application to run as a Windows Service (not a scheduled task). What is the easiest way to convert this console application into a Windows Service using Visual Studio .Net? Asad
23
2642
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me in a direction to find info on how to prevent and/or fix the db's so that these message don't pop up when the app is started. Error messages below: 1. Microsoft Jet 4.0 service pack 8 must be installed to block unsafe expressions without...
4
4175
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
3
13790
by: =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post by:
Now I have a web application, a web service and a SQL Server database. The Web application will invoke the web service, the web service invokes the SQL Server stored procedure. I let the web service run in an application pool which runs under a domain user, this domain user has permissions of accessing database and the connection to database is trusted connection. All these work well. The web application will be used in internet (not...
2
2542
by: skumardss | last post by:
Hi Techees... We have a Windows C# Application (Business Layer) which does communicate between the User Interface Layer and Data Layer. We need to convert this application to a Windows Service. We tried creating Windows Service Application in .NET framework and refered the dll of the Business Layer and then invoked the main method of the Busines Layer within the OnStart event of the Service Application. Once after doing this we were able...
0
8468
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6213
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2041
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.