-1
특정 프로세스가 실행 중인지 5 초마다 확인한 다음 간단한 프로세스를 작성하려고 시도하는 간단한 프로그램을 작성하려고합니다. 프로그램은 백그라운드에서 실행되어야하며 시스템이 시작될 때마다 시작되어야합니다. VB로 작성 그 지금까지 프로세스 :프로세스를 스캔 한 다음 발견되면 다시 죽이고 다시 시작하십시오.
Module Module1
Private Declare Auto Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
Private Declare Auto Function GetConsoleWindow Lib "kernel32.dll"() As IntPtr
Private Const SW_HIDE As Integer = 0
Sub Main()
eh:
Dim hWndConsole As IntPtr
hWndConsole = GetConsoleWindow()
ShowWindow(hWndConsole, SW_HIDE)
For Each proc As Process In Process.GetProcessesByName("hl") 'hl is the process to look for
proc.WaitForExit(5000) 'wait up to 5 seconds.
proc.Kill() 'force the process to exit.
Next proc
GoTo eh
Threading.Thread.Sleep(5000) 'Sleep for 5 sec and start over
End Sub
End Module
그러나 문제는, 그것은 매번 콘솔 창을 보여줍니다 그것은 시작하고, 검출 공정 물론
감사 요 당신이 이미 사망 한 프로세스를 검색 응답을 위해. 내가 제안한대로 변경되었지만 프로세스가 종료 된 후 프로세스가 사용자에 의해 다시 시작된 후에도 여전히 충돌합니다. – degaro
우선,'Try Catch'를 사용하면 오류를 더 잘 처리 할 수 있습니다. 그리고이 코드를'별도의 스레드 '에서 실행하는 것이 좋습니다. Try를 사용하여 코드를 편집 한 후에 오류 메시지를 알려주십시오. – Tyler