Creating Needed Installers for Windows Services

 

This is not the Actual “Installer”. This is code needed for the Service to operate correctly.

We will get to Installing and Deploying Later…

 

Add the Installer Code:

From Service1 designer, right click in the gray area and choose Add Installer.

serviceblank

Another file will be added to your Solution Explorer, called ProjectInstaller.  On this class will be to components in the designer, ServiceProcessInstaller1, and ServiceInstaller1.

Lets configure the Installer:  Click on the listed component and alter the following properties:

ServiceProcessInstaller1:

  • Account = LocalSystem   (will cause service to run under local service account)
  • serviceProperties1

    ServiceInstaller1

  • ServiceName = NewService
  • StartType = Automatic     (Whether your service will auto start after reboot)
  • DisplayName =  NewService
  • serviceProperties2

    Now we will Build and Install the service to test it out.

    Services Part 3:>  Build and Install your Windows Service

     

     

    Programmers – Use your talents to make some money online.  Click Here to Read More

    Creating Services with Visual Studio 2008

     

    A Windows services is a application that runs in the background.  There is documentation on the Web for creating a Service with Visual Studio 2003, but is is changed for VS 2005, and 2008.

     

    I will walk thru a sample Service in Visual Studio 2008.  This should also work with VS 2005.

     

     

    Create the Service.


     

     

    servicecreate

     

    From Visual Studio Start Page, choose create project…   Select Windows Service and give it a name of NewService.

     

    serviceblank

    First thing we will do is add a timer to the Service.  DO NOT USE THE TIMER IN THE TOOLBOX.  The Timer for Windows Forms does not work for Services.  We will have to find the System.Timers.Timer component by right clicking on the Toolbox, and Choose Items.

    Find the one that matches below:
    servicetimerchoose

     

    Click OK.  This will put the Timer into the Printing section of the Toolbar for some reason.

     

    From The Service1 designer.  Click on Timer1, and set the interval to 10000 (10 Seconds).  Then Double-click to open Code View for Timer1_Elapsed.

    Add the Following Code to the Timer1_Elapsed:

    Dim MyLog As New EventLog() 
    ‘ create a new event log 
    ‘ Check if the the Event Log Exists

    If Not MyLog.SourceExists(“NewService”) Then 
    MyLog.CreateEventSource(“NewService”, “NewService_Log”) ‘ Create Log
    End If 

    MyLog.Source = “NewService” ‘ Write to the Log 
    MyLog.WriteEntry(“NewService_Log”, “Service is Running” _ , EventLogEntryType.Information)

    End Sub

     

    And For OnStart():

     

    Protected Overrides Sub OnStart(ByVal args() As String)
    ‘ Add code here to start your service. This method should set things 
    ‘ in motion so your service can do its work. 

    Timer1.Enabled = True
    End Sub

     

    Now is normally where you would hit Run to start and debug your app.  This is not the case with Windows Services.  We have to add a few things called Installers to make them work correctly.

     

    Services Part 2:>  Creating the needed Installers

     

     

    Programmers – Use your talents to make some money online.  Click Here to Read More