Create project in Visual Studio to run as a service

Posted on 2011-10-31
Last Modified: 2012-05-12
I have a project created in Visual Studio.  The project works properly.  However, I install it on my customers' system by logging in using remote desktop (they are in a different state).  The program is written to launch every hour on the hour.  I also put the .exe in the Startup folder so if the server reboots, the program will launch automatically.

All of that works fine.  But the problem is that, because I logged in using rdp to install the package, as soon as I log out, the program closes and, consequently does not run hourly as it is supposed to.  If I log back in, the Startup folder launches the program again so it looks like it was running all along, but the files that are supposed to be created on the hour, were not created.  If I click the exit button to get out of remote desktop, rather than logging out, the program continues to run and gives me hourly file creation.  But that is not really an acceptable workaround.

What I am wondering is if it is possible to create the install package so this program runs as a service and will not be affected by my remote desktop user login?



Question by:thoecherl
    LVL 9

    Accepted Solution

    Here is a page on how to create a service (quickly, it is a different project type).

    Though, you can use a batch file to start your program, which you set to be launched by the Windows scheduler every hour. (From my test, Windows Application built by .NET are not loadable from the scheduler, so that's why the .BAT)

    Using this method, you will have to ensure your program is not already running. Looking into the running processes will tell you that. If it is already running, close new instance, otherwise, launch.
    LVL 83

    Assisted Solution

    >What I am wondering is if it is possible to create the install package so this program runs as a service

    As said above, its not an installer that can transform your exe into service. Service is a totally different project template and may require rewritting/refactoring/rearchitecting your code.


    Author Closing Comment


    Thanks for the input.  The every hour part of the program is written into it.  Right now I leave it running all the time and every hour, on the hour, a file is downloaded from a particular website to a designated location.  Then it is copied to an archive folder and renamed.  This works, as long as the program is running.  So I am not concerned about how to schedule it to run every hour.  I want it to run constantly -- even when I log off the server.  But right now, the log off process terminates the program until I log back in.  I was hoping if I could run it as a service it would continue to run even if I logged off.

    But you and CodeCruiser have both told me that I have to start over and create a new project and probably make changes to the code.  I think I will first test to see if someone launches the program at the server console, if that takes care of the problem.  If not, I will create a service project and may need to open another case to ask for your help.  Thanks.


    This is the project that you helped me with to download a file from a website every hour.  I'm happy with the way that turned out, but now I have discovered this new problem.  I will try the solution that I mentioned above in my note to djon2003, but if that doesn't solve the issue, I will create a new project as a service and probably ask for additional help.  Thanks again.

    LVL 9

    Expert Comment

    Just to add that the scheduler part is to ensure that tour app is constantly running. Though, I see your problem. You can auto start a particular session on boot so that there is always at least one session running. That allows the scheduler to run any time. more, using this trick, you can start your software into that session. The scheduler is still useful to prevent software closed any how.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now