windows服务问题。
第一次做,步骤如下:
1.新建windows服务项目。
2.在两方法中显示一消息,其他没写任何代码。
Protected Overrides Sub OnStart(ByVal args() As String)
' 在此处添加启动服务的代码。此方法应设置具体的操作
' 以便服务可以执行它的工作。
MsgBox("服务启动")
End Sub
Protected Overrides Sub OnStop()
' 在此处添加代码以执行停止服务所需的关闭操作。
MsgBox("服务停止")
End Sub
3.在ServiceProcessInstaller1属性中Account属性改为LocalService
在ServiceInstaller1属性中ServiceName属性改为MyServer,StartType属性改为Automatic
然后生成项目
4.用installutil.exe 命令安装,并显示安装成功。
5.在服务管理器中找到新建的服务MyServer,并启动它。
结果报错:在本地计算机无法启动MyServer服务。服务并未返回错误。这可能是一个window内部错误或服务内部错误。如果问题持续存在,请与您的管理员联系。
请问我是哪一步出错了,该怎么解决啊,请高手指点。
问题点数:50、回复次数:5Top
1 楼duan17()回复于 2005-07-22 16:21:19 得分 5
服务不能有界面Top
2 楼WTaoboy(SnowMans)回复于 2005-07-22 16:35:25 得分 5
http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/ServiceApplication/SimpleService/SimpleService.src
这是有一段非常简单的编写windows 服务的方法Top
3 楼wangsaokui(无间道III(终极无间)C#MVP)回复于 2005-07-22 17:07:23 得分 0
MsgBox不能用在windows service中Top
4 楼wangsaokui(无间道III(终极无间)C#MVP)回复于 2005-07-22 17:09:40 得分 35
msgbox不能用在windows service中,你可以写在日志中
Imports System
Imports System.Diagnostics
Imports System.Threading
Protected Overrides Sub OnStart(ByVal args() As String)
' 在此处添加启动服务的代码。此方法应设置具体的操作
' 以便服务可以执行它的工作。
' Create the source, if it does not already exist.
If Not EventLog.SourceExists("MySource") Then
EventLog.CreateEventSource("MySource", "MyNewLog")
Console.WriteLine("CreatingEventSource")
End If
' Create an EventLog instance and assign its source.
Dim myLog As New EventLog()
myLog.Source = "MySource"
' Write an informational entry to the event log.
myLog.WriteEntry("Writing to event log.")
End Sub 'Main
Top
5 楼minmin071400()回复于 2005-07-22 17:25:05 得分 5
在ServiceProcessInstaller1属性中Account属性改为LocalService
改为LocalSystemTop




