using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Text;namespace WindowsService1 { public partial class Service1 : ServiceBase { Form1 F = null; System.Windows.Forms.Timer T = new System.Windows.Forms.Timer(); public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { // TODO: 在此处添加代码以启动服务。 (F = new Form1()).Show(); } protected override void OnStop() { // TODO: 在此处添加代码以执行停止服务所需的关闭操作。 } } } 然后添加一个form using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsService1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); notifyIcon1.Icon = this.Icon; notifyIcon1.Visible = true; } } }服务帐户改为LocalSystem安装完服务后,在控制面板->服务里选你的服务右键属性->登录->本地系统帐户->打勾允许服务和桌面交互
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Text;namespace WindowsService1 { public partial class Service1 : ServiceBase { Form1 F = null; System.Windows.Forms.Timer T = new System.Windows.Forms.Timer(); public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { // TODO: 在此处添加代码以启动服务。 (F = new Form1()).Show(); } protected override void OnStop() { // TODO: 在此处添加代码以执行停止服务所需的关闭操作。 } } } 然后添加一个form using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;namespace WindowsService1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); notifyIcon1.Icon = this.Icon; notifyIcon1.Visible = true; } } }服务帐户改为LocalSystem安装完服务后,在控制面板->服务里选你的服务右键属性->登录->本地系统帐户->打勾允许服务和桌面交互
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
Form1 F = null; System.Windows.Forms.Timer T = new System.Windows.Forms.Timer(); public Service1()
{
InitializeComponent(); } protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。 (F = new Form1()).Show();
} protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
}
然后添加一个form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsService1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); notifyIcon1.Icon = this.Icon;
notifyIcon1.Visible = true;
}
}
}服务帐户改为LocalSystem安装完服务后,在控制面板->服务里选你的服务右键属性->登录->本地系统帐户->打勾允许服务和桌面交互
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
Form1 F = null; System.Windows.Forms.Timer T = new System.Windows.Forms.Timer(); public Service1()
{
InitializeComponent(); } protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。 (F = new Form1()).Show();
} protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
}
然后添加一个form
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsService1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); notifyIcon1.Icon = this.Icon;
notifyIcon1.Visible = true;
}
}
}服务帐户改为LocalSystem安装完服务后,在控制面板->服务里选你的服务右键属性->登录->本地系统帐户->打勾允许服务和桌面交互
http://topic.csdn.net/u/20070508/20/e8a9e73a-f4ee-433d-9628-dde2ceb86e1d.html
csdn又抽了
服务程序
服务配置程序
服务控制程序你要分清.
想交互在服务里实现 启动、暂停、关闭等等方法。
在Winform里通过Windows服务方法调用接口就好了。
服务程序
服务配置程序
服务控制程序