473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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.EXE) /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 6728
Todd Jaspers <To*********@discussions.microsoft.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*********@discussions.microsoft.comwrote in message
news:BB**********************************@microsof t.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*********@discussions.microsoft.comwrote in message
news:48**********************************@microsof t.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

"EmeraldShield" 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*********@discussions.microsoft.comwrote in message
news:BB**********************************@microsof t.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

"EmeraldShield" 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*********@discussions.microsoft.comwrote in message
news:BB**********************************@microsof t.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
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...
5
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...
3
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...
2
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 =...
2
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...
23
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...
4
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...
3
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...
2
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. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.