0

下面的内容可能有一些问题。还没有机会测试/调试代码,因为无法运行它。它指出没有找到主要方法。但是还有?我什至将其更改为共享等。这可能很明显?

它正在标记 - 在“ConsoleApplication1.Module1”错误中找不到“Sub Main”。

此外,主要方法并不总是一个单独的类,我只是在尝试一些东西。我正在导入一个参考 - system.processes。最初创建为 vb.form 但意识到我不想要表单部分并重新创建为控制台应用程序(这很可能是问题所在,因为它是我完成的第一个控制台应用程序之一)。

代码基本上是计划在服务死亡时采取行动。报告并尝试管理重启(未完成,欢迎提出想法)。

Imports System
Imports System.Management
Imports System.ServiceProcess
Imports System.Diagnostics
Imports System.Threading
Imports System.IO

Module Module1


Public Class Control


    Public Sub Main()              'Public Sub Main(ByVal sArgs() As String)
        Dim restart As New Rest

        restart.startTime = DateTime.Now()
        restart.cr20Services()
        restart.Report()
    End Sub

End Class

Public Class Rest
    public startTime As String
    Dim logPath As String = "C:\cr20\restart.txt"
    'Dim fileExists As Boolean = File.Exists(strFile)
    Dim arrcr20ServicesInitialStatus As New ArrayList
    Dim failedServices As New ArrayList
    Dim arrcr20Services As New ArrayList


    Public Sub cr20Services()

        'cr20 Services
        arrcr20Services.Add("cr20 service")
        arrcr20Services.Add("cr20 router")


        For Each cr20Service In arrcr20Services

            arrcr20ServicesInitialStatus.Add(cr20Service & " - " & cr20Status(cr20Service))
            cr20Restore(cr20Service)

        Next


    End Sub

    Private Function cr20Status(ByVal cr20Service As String)

        Dim service As ServiceController = New ServiceController(cr20Service)

        Return service.Status.ToString


    End Function



    Private Sub cr20Restore(ByVal cr20Service As String)

        Dim service As ServiceController = New ServiceController(cr20Service)

        'Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("calc") 

        If (service.Status.Equals(ServiceControllerStatus.Stopped)) Or (service.Status.Equals(ServiceControllerStatus.StopPending)) Then

            failedServices.Add(service)
            service.Stop()
            Thread.Sleep(10000)     'give service 10 seconds to stop
            service.Start()

        End If

    End Sub
4

0 回答 0