如何创建一个 Windows 服务应用程序的安装项目在 Visual C# 中
来源:互联网 发布:java 循环替换字符串 编辑:程序博客网 时间:2024/05/18 03:11
本节描述如何创建 Windows 服务项目,以及如何使用已编译的安装项目来安装 Windows 服务。 您完成在上一节可以配置 Windows 服务项目的步骤之后,请按照下列步骤,以便可以安装服务应用程序打包服务应用程序的部署项目中添加操作:对于 Windows 服务创建安装项目
创建 Windows 服务项目
注意Visual Studio 2005 或 Visual Studio 2008 中展开 Visual C#项目类型 下,单击Windows,然后单击 模板 下的 Windows 服务。EventLog.WriteEntry("My simple service started.");
安装 Windows 服务使用经过编译的安装项目
请注意在 安装、 提交、 回滚 和 卸载 下显示的 主输出。完成代码列表
Service1.cs
using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.ServiceProcess;namespace LogWriterService{public class Service1 : System.ServiceProcess.ServiceBase{/// <summary> /// Required designer variable./// </summary>private System.ComponentModel.Container components = null;public Service1(){// The Windows.Forms Component Designer must have this call.InitializeComponent();// TODO: Add any initialization after the InitComponent call}// The main entry point for the processstatic void Main(){System.ServiceProcess.ServiceBase[] ServicesToRun;// More than one user service may run in 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(){components = new System.ComponentModel.Container();this.ServiceName = "Service1";}/// <summary>/// Clean up any resources that are 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){EventLog.WriteEntry("My simple service started.");} /// <summary>/// Stop this service./// </summary>protected override void OnStop(){// TODO: Add code here to perform any tear-down necessary to stop your service.}}}
验证它工作的
- 在 $ 控制面版中双击 管理工具,然后双击 服务
- 用鼠标右键单击 服务 1,然后单击 开始
- 使用下列方法之一验证在事件日志中会记录一个事件:
- 方法 1
- 在 $ 控制面版中双击 管理工具,然后双击 事件查看器。
- 在左窗格中单击 应用程序日志,然后找到事件日志中有您的服务,在右窗格中。
- 方法 2
- 在服务器资源管理器中,展开 服务器,展开 ComputerName,展开 事件日志、 展开 应用程序,然后展开 服务 1。 记住 服务 1 是在的类不是该服务的名称本身。因此,服务 1 用作应用程序的名称。 (它是超出了本文介绍如何自定义名称的范围。
- 将光标移至日志条目。从顶部开始第二个条目应阅读"我的简单服务启动
- 方法 1
引用http://support.microsoft.com/kb/816169/zh-cn
- 如何创建一个 Windows 服务应用程序的安装项目在 Visual C# 中
- 如何在 VisualC # .NET 和 VisualC # 2005 中创建安装项目用于 Windows 服务应用程序
- C#创建、安装一个Windows服务
- C#创建、安装一个Windows服务
- C#创建、安装一个Windows服务
- C#创建、安装一个Windows服务
- 如何使用Visual C#来创建Windows服务程序
- C#中 如何创建Windows服务?
- 如何在 Windows Phone 的代码中创建应用程序栏
- .Net中如何创建一个Windows服务
- 如何创建 MFC 应用程序在 Visual C++ 中没有菜单栏
- 如何创建一个标准的Windows服务
- 用Visual C#创建Windows服务程序
- 用Visual C#创建Windows服务程序
- 用Visual C#创建Windows服务程序
- 用Visual C#创建Windows服务程序
- 用Visual C#创建Windows服务程序
- 用Visual C#创建Windows服务程序
- 【TUP第五期】来自一线的移动开发秘诀
- 创建删除外键的SQL(转)
- CSDN总编观察:创新与山寨——《程序员》2010第10期卷首语
- 惊喜
- Fedora 13 telnet配置
- 如何创建一个 Windows 服务应用程序的安装项目在 Visual C# 中
- 浅析Oracle存储过程触发器在数据同步中的应用
- Assignment 1: PL/SQL stored procedure P9
- SQL FOREIGN KEY 约束的建立与删除(转)
- GAIA page
- 关于错误:"table is mutating, trigger/function may not see it
- 关于UUID,GUID,OCMB
- 正则表达式
- 规划分析输出表格设计思路(2010_09)