惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
A
Arctic Wolf
K
Kaspersky official blog
T
Threat Research - Cisco Blogs
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
U
Unit 42
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cisco Blogs
AWS News Blog
AWS News Blog
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
美团技术团队
T
Threatpost
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cyber Attacks, Cyber Crime and Cyber Security
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
C
Cybersecurity and Infrastructure Security Agency CISA
F
Full Disclosure
博客园_首页
N
Netflix TechBlog - Medium
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Register - Security
The Register - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Announcements
Recent Announcements
博客园 - Franky
P
Palo Alto Networks Blog
Project Zero
Project Zero
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Cisco Talos Blog
Cisco Talos Blog
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 【当耐特】
GbyAI
GbyAI

博客园 - 末世纪狂潮

[导入]Pylogs v1.14beta (正式支持Django 1.0) 发布 [导入]Django中动态改变ImageField和FileField中文件的上传路径 [导入]Tech·ED 2008 票到了。。。 [导入]ASP.NET获取客户端IP地址的几点补充[转载] - 末世纪狂潮 - 博客园 [导入]Windows Live Mail不能启动的解决办法 - 末世纪狂潮 [导入]Linux Mint中文语言包 [导入]XPS 1530安装MAC OsX 10.5.2指南 [导入]奥运加油,中国加油 [导入]IE7打不开微软的首页了? [导入]linux下常用格式的压缩与解压方法 [导入]利用PIL生成水印图片或文字 [导入]Pylogs v1.12beta发布 test live write write blog 测试tb .NET中实现无刷新客户端联动下拉菜单 "百万首页"深度思考 QQ天气预报代码 QQ登录没反应解决方法,及新版QQ的一个BUG 要开始学JAVA了,郁闷中。。。
用C#写一个简单的WINDOWS服务程序
末世纪狂潮 · 2006-10-12 · via 博客园 - 末世纪狂潮

服务程序在C#中的写法。
        1.在VS.NET2003中新建一个WINDOWS服务程序的项目WinSrv_A。
        2.更改SERVICE1.CS属性SERVICENAME为你所要建立的服务名称,在服务管理器->名称中你可以看到你的服务名
        3.按F7进入代码窗口,里面有2个重载函数是你要在其中写代码的一个是
            //protected override void OnStart(string[] args)
            //{...} //这个函数是你启动服务后执行的函数
            //protected override void OnStop()
            //{...}//这个函数是你停止服务后执行的函数
           

            我这里简单的做一个记录启动和终止服务的时间的功能。写如日志文档。
           
            protected override void OnStart(string[] args)
            {
                   // TODO: 在此处添加代码以启动服务。
                   String s = System.DateTime.Now.ToString();
                   if(!File.Exists("c:\\srvlog.txt"))
                   {
                        StreamWriter sr = File.CreateText("c:\\bbbirdlog.txt");
                        sr.WriteLine("-------------------------START SRV---------------------");
                        sr.WriteLine ("我的新服务在{0}时间开始",s);
                        sr.WriteLine ("我可以写整型 {0} or 浮点型 {1},等等.",1, 4.2);
                        sr.Close();
                   }
                   else
                   {
                       StreamWriter sr = File.AppendText("c:\\bbbirdlog.txt");
                       sr.WriteLine("-------------------------START SRV---------------------");
                       sr.WriteLine ("我的新服务在{0}时间开始",s);
                       sr.WriteLine ("我可以写整型 {0} or 浮点型 {1},等等.",1, 4.2);
                       sr.Close();
                   }
              }
 
               /// <summary>
               /// 停止此服务。
               /// </summary>
               protected override void OnStop()
               {
                        // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
                        String s1 = System.DateTime.Now.ToString();
                        if(!File.Exists("c:\\srvlog.txt"))
                        {
                         StreamWriter sr = File.CreateText("c:\\bbbirdlog.txt");
                         sr.WriteLine("-------------------------STOP SRV---------------------");
                         sr.WriteLine ("我的新服务在{0}时间停止",s1);
                         sr.Close();
                        }
                        else
                        {
                         StreamWriter sr = File.AppendText("c:\\bbbirdlog.txt");
                         sr.WriteLine("-------------------------STOP SRV---------------------");
                         sr.WriteLine ("我的新服务在{0}时间停止",s1);
                         sr.Close();
                         }
                   }
               
            4.回到设计窗口点右键选择添加安装程序生成serviceInstaller1和serviceProcessInstaller1两个组件
               把serviceInstaller1的属性ServiceName改写为你的服务程序名,并把启动模式设置为AUTOMATIC
               把serviceProcessInstaller1的属性account改写为LocalSystem
            5.编译链接生成服务程序。
            6.用.net framework工具INSTALLUTIL安装服务程序即可。