Vb.net 在windows xp上安装windows服务
我正在尝试在windows XP上安装我在Visual Studio 2012中创建的windows服务。我该怎么做 我试着遵循这个教程,但在实现它时运气不佳 我的代码有什么问题吗Vb.net 在windows xp上安装windows服务,vb.net,windows,windows-services,windows-xp-sp3,Vb.net,Windows,Windows Services,Windows Xp Sp3,我正在尝试在windows XP上安装我在Visual Studio 2012中创建的windows服务。我该怎么做 我试着遵循这个教程,但在实现它时运气不佳 我的代码有什么问题吗 Public Class MyFirstService Dim WithEvents timer1 As New System.Timers.Timer Protected Overrides Sub OnStart(ByVal args() As String) timer1.Interval =
Public Class MyFirstService
Dim WithEvents timer1 As New System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
timer1.Interval = 10000
timer1.Start()
WriteLog(Me.ServiceName & " has started ...")
End Sub
Protected Overrides Sub OnStop()
WriteLog(Me.ServiceName & " has stopped ...")
End Sub
Private Sub timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles timer1.Elapsed
WriteLog(Me.ServiceName & " is running ...")
End Sub
Private Sub WriteLog(ByVal strMessage As String)
Dim strPath As String, file As System.IO.StreamWriter
strPath = AppDomain.CurrentDomain.BaseDirectory & "\MyService.log"
file = New System.IO.StreamWriter(strPath, True)
file.WriteLine("Test")
file.Close()
End Sub
End Class
当我单击my.exe时,会收到以下错误消息MyFirstService.exe不是有效的Win32应用程序。这是我第一次尝试窗口服务应用程序 我最近开发了几个Windows服务,希望能够轻松地调试它们,而不必每次构建服务时都在命令提示符中输入大量内容 为此,我首先在我的服务项目的项目属性中将以下内容添加到我的构建事件中: 建造后:
call "$(DevEnvDir)..\Tools\vsvars32.bat"
installutil "$(TargetPath)"
net start "$(SolutionName)"
使用上述方法成功构建后,请确保将以下内容添加到预构建中:
net stop "$(SolutionName)"
call "$(DevEnvDir)..\Tools\vsvars32.bat"
installutil /u "$(TargetPath)"
这将使您的项目在构建时自动停止、卸载、重新安装和启动。还要确保在成功生成时运行生成后事件
注意:这确实假设您的服务名称与您的解决方案名称相同。如果它们不同,您将希望将$SolutionName更改为您的服务名称。好吧,您的代码不会尝试安装任何东西,因此我不确定您在问什么。您在安装或运行服务时遇到问题吗?正在安装服务。在安装正确之前,我无法运行它?你说我的代码没有安装任何东西是什么意思?当我单击my.exe时,我会收到错误消息MyFirstService.exe不是有效的Win32应用程序。如果是这种情况,则说明它编译不正确。是的,您可以在安装之前运行它。大多数服务只是接收附加信号的EXE。可能的重复