#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    73
    Rep Power
    16

    installing windows service


    Hi! i wrote a simple windows service which writes to a file when started and stoped. I'm using visual studio under windows xp professional. Here is my code:

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.ServiceProcess;
    using System.IO;


    namespace mcWinService
    {
    public class Service1 : System.ServiceProcess.ServiceBase
    {
    StreamWriter file;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public Service1()
    {
    // This call is required by the Windows.Forms Component Designer.
    InitializeComponent();

    // TODO: Add any initialization after the InitComponent call
    }

    // The main entry point for the process
    static void Main()
    {
    System.ServiceProcess.ServiceBase[] ServicesToRun;

    // More than one user Service may run within the same process. To add
    // another service to this process, change the following line to
    // create a second service object. For example,
    //
    // ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
    //
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    //
    // Service1
    //
    this.ServiceName = "paulService";

    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    /// <summary>
    /// Set things in motion so your service can do its work.
    /// </summary>
    protected override void OnStart(string[] args)
    {
    // TODO: Add code here to start your service.
    file = new StreamWriter( new FileStream("ServiceTest.log", System.IO.FileMode.Append ) );
    this.file.WriteLine("Starting Service");
    this.file.Flush();
    }

    /// <summary>
    /// Stop this service.
    /// </summary>
    protected override void OnStop()
    {
    // TODO: Add code here to perform any tear-down necessary to stop your service.
    this.file.WriteLine("Stopping Service");
    this.file.Flush();
    this.file.Close();

    }
    }
    }

    After building it, I installed it with installutil. Heres the InstallUtil.InstallLog:


    Running a transacted installation.

    Beginning the Install phase of the installation.
    See the contents of the log file for the c:\documents and settings\paul rivera\my documents\visual studio projects\mcwinservice\bin\debug\mcwinservice.exe assembly's progress.
    The file is located at c:\documents and settings\paul rivera\my documents\visual studio projects\mcwinservice\bin\debug\mcwinservice.InstallLog.

    The Install phase completed successfully, and the Commit phase is beginning.
    See the contents of the log file for the c:\documents and settings\paul rivera\my documents\visual studio projects\mcwinservice\bin\debug\mcwinservice.exe assembly's progress.
    The file is located at c:\documents and settings\paul rivera\my documents\visual studio projects\mcwinservice\bin\debug\mcwinservice.InstallLog.

    The Commit phase completed successfully.

    The transacted install has completed.


    After installing, I cant find the service in the services part when I manage my computer. Any ideas? =)
    Last edited by paulr1984; September 6th, 2003 at 12:34 AM.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    1
    Rep Power
    0

    installer


    I had this problem and solved it by adding an installer, explained here:
    http://www.developerfusion.com/show/3441/3/

IMN logo majestic logo threadwatch logo seochat tools logo