• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

Create VB.net project in Visual Studio to run as a service

I have a VB.net 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?



  • 2
2 Solutions
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.
>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.

thoecherlAuthor Commented:

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.

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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now