VB.Net
  Home arrow VB.Net arrow Page 3 - Creating A Windows Service in VB.NET
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VB.NET

Creating A Windows Service in VB.NET
By: Jayesh Jain
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 262
    2002-10-04

    Table of Contents:
  • Creating A Windows Service in VB.NET
  • What is Windows Service
  • Adding an Installer to the Project
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating A Windows Service in VB.NET - Adding an Installer to the Project


    (Page 3 of 4 )

    Open the service1.vb design window, right click on it and select Add Installer option, which will add an installer project (called ProjectInstaller.vb) with two controls -- ServiceProcessInstaller1 and ServiceInstaller1 -- to our existing project.

    Select the ServiceInstaller1 control and open the property window. Change the ServiceName property and DisplayName property to MyService (this is the name you want to appear in the list of services in the services window).

    Select the ServiceProcessInstaller1 control and open the property window. Change the Account property to LocalSystem (this needs to be specified as we need to run the service on our local machine).

    Now it's time for us to build the application and create an executable. Select Build Solution from the Build menu to create an executable with installation instructions for the service.

    Installing the Service
    To install our service we need to use the InstallUtil program, which is a .NET utility to install Windows services. You can it in C:\ WINNT\ Microsoft.NET\ Framework\ v1.0.3705

    This directory might be different on your computer, depending upon the version of the .NET framework you are working with.

    Alternatively, you could run a .NET Command Window by selecting Start –> Programs -> Microsoft Visual Studio .NET -> Visual Studio .NET Tools >- Visual Studio .NET Command Prompt, which sets all of the required paths for you.

    Type the following command in the command window:

    InstallUtil C:\tgol\Myservice\Bin\Myservice.exe

    Tthis is the path for the executable of the service we just created. Remember that VB.NET created the executable in the Bin folder under the project folder, so make sure you change this to your executable path.



    Starting the Service
    Running a service and starting a service are two different things -- when you install the service with InstallUtil you are running the service, but have yet have to start it.

    To view and start the service, open Control Panel -> Administrative Tools. Now click Services, locate MyService, right click on it and select Start to start it:



    Our service is now started. Open the Event Viewer from Administrative Tools and click Application Log to see the logs created by the Service (MyService) every 10 seconds. If you don't see any logs click refresh (F5). You will have to keep refreshing to see the latest event logs:



    Stopping the Service
    This procedure is similar to installing the service but now we shall run the InstallUtil with the /U parameter, which will uninstall the service:

    InstallUtil /U C:\tgol\Myservice\Bin\Myservice.exe (or the executable path on your computer).

    Take note of the message to confirm that the service was uninstalled properly.

    Tips
    • Stop the service and close the service window before you install/uninstall the service.
    • Always uninstall/install if you make any changes to the service application.
    • Try avoiding a user interface, inputs and message boxes in the service application.
    • Open ProjectInstaller.vb, select the ServiceInstaller1 control, and open the property window. Change the StartType property to automatic if you want to start the service automatically.

    More VB.Net Articles
    More By Jayesh Jain


       · Windows XP ProVB2005When I add the Timer from tool bar the tick event wont...
       · Same problem here, XP Pro / VS2008. OnStart and OnStop fire, but timer won't.
     

    VB.NET ARTICLES

    - MyClass - Implementing Polymorphism in VB.Net
    - Building a News Ticker Using VB.Net
    - Everything You Wanted to Know About Forms In...
    - Building Assemblies with VB.Net
    - Simple VB.NET Notify Icon with Panel Applica...
    - Regular Expressions in .NET
    - String Encryption With Visual Basic .NET
    - Deploying Applications in VB.NET: Part 1/2
    - Watching Folder Activity in VB.NET
    - Creating A Windows Service in VB.NET
    - Implementing The Google Web Service In VB.NET
    - Migrating to Visual Basic.NET from Visual Ba...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT