1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
Imports System Imports System.ServiceProcess Imports System.IO Imports System.Threading Module Module1 Sub Main() '============================================================== ' ОПИСЫВАЕМ ПЕРЕМЕННЫЕ - DIM BLOCK '============================================================== Dim vNPrintingLogPath As String, vToday As String, vNow As Date, vLastTime As Date Dim vMinDuration As Int32, vMinDurationFileName Dim files As New List(Of String) Dim fs As Object Dim vDuration As TimeSpan Dim myController = New ServiceController Dim processes() As Process = Process.GetProcesses Dim processName As String '============================================================== ' ЗАДАЕМ ПЕРЕМЕННЫЕ & ОБЪЕКТЫ '============================================================== vNPrintingLogPath = "C:\Users\Public\Documents\NPrinting\Log\" vToday = Today.ToString("yyyyMMdd") vNow = Now fs = CreateObject("Scripting.FileSystemObject") '============================================================== ' АЛГОРИМТ ПРОВЕРКИ '============================================================== vMinDuration = 9999999 ' Исходное значение '=== Получаем последний обновленный файл по сегодняшнему дню For Each foundFile As String In My.Computer.FileSystem.GetFiles( vNPrintingLogPath, FileIO.SearchOption.SearchTopLevelOnly, vToday & "*_NPrintingSvc.log") vLastTime = System.IO.File.GetLastWriteTime(foundFile) vDuration = vNow - vLastTime If vDuration.TotalMinutes < vMinDuration Then vMinDuration = vDuration.TotalMinutes vMinDurationFileName = foundFile End If Next '=== ЕСЛИ vMinDuration > 60 минут, то требуется убить qv.exe и рестартануть NPrinting службу If vMinDuration > 60 Then '=== 1. KILL Qv.exe For p As Integer = processes.Count - 1 To 0 Step -1 processName = processes(p).ProcessName.ToLower() If processName = "qv" Then '=== УБИТЬ ПРОЦЕСС NPrintingService.exe processes(p).Kill() '=== ЖДЕМ 3 секунды 'Console.WriteLine("Ждем 3 секунды. " & processName & " завершен.") Threading.Thread.Sleep(3000) End If Next '=== 2. KILL NPrintingSvc.exe For p As Integer = processes.Count - 1 To 0 Step -1 processName = processes(p).ProcessName.ToLower() If processName = "nprintingsvc" Then 'processName = "qv" Or '=== УБИТЬ ПРОЦЕСС NPrintingService.exe processes(p).Kill() '=== ЖДЕМ 3 секунды Threading.Thread.Sleep(3000) '=== ЗАПУСКАЕМ NPrintingService myController.ServiceName = "NPrintingService" myController.MachineName = "server-qv-name" myController.Start() Threading.Thread.Sleep(1000) End If Next Else Console.WriteLine("Рестарт не требуется") End If End Sub End Module |
Подписаться
0 комментариев