IMPEDIR FECHAMENTO DE PROCESSO
Olá a todos,
Eu preciso criar um pequeno aplicativo para monitorar um processo de um programa especifico, e que se caso ele for fechado o aplicativo reabra ele automaticamente.
Esse aplicativo precisa ser implantado em duas maquinas na empresa que trabalho, alguém conhece alguma rotina que faça isso ? Estou meio perdido...
Eu preciso criar um pequeno aplicativo para monitorar um processo de um programa especifico, e que se caso ele for fechado o aplicativo reabra ele automaticamente.
Esse aplicativo precisa ser implantado em duas maquinas na empresa que trabalho, alguém conhece alguma rotina que faça isso ? Estou meio perdido...
Fiz isso uma vez ...rsrsr
Achei aqui mas nem testei, dá uma olhada.
Option Explicit
Private Const TH32CS_SNAPPROCESS As Long = 2
Private Const MAX_PATH As Long = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib [Ô]kernel32[Ô] (ByVal lFlags As Long, _
ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib [Ô]kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib [Ô]kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib [Ô]kernel32[Ô] (ByVal hPass As Long)
Dim strPath As String
Public Function AppIsRunning(ByVal AppName As String) As Boolean
Dim Process As PROCESSENTRY32
Dim hSnapShot As Long
Dim r As Long
AppName = LCase$(AppName)
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot <> -1 Then
Process.dwSize = Len(Process)
r = Process32First(hSnapShot, Process)
Do While r
If LCase$(Left$(Process.szExeFile, InStr(1, Process.szExeFile, vbNullChar) - 1)) = AppName Then
AppIsRunning = True
r = False
End If
r = Process32Next(hSnapShot, Process)
Loop
CloseHandle hSnapShot
End If
End Function
Private Sub Form_Load()
App.TaskVisible = False
strProcessoAtivo = fncLeIni([Ô]Parametros[Ô], [Ô]Processo[Ô])
If strProcessoAtivo = [Ô]SIM[Ô] Then
strPath = App.Path & [Ô]\[Ô]
If AppIsRunning([Ô]PROCESSOATIVO.EXE[Ô]) = False Then
WinExec strPath & [Ô]PROCESS_A_SER_EXECUTADO.EXE[Ô], 10
End If
Else
Exit Sub
End If
End Sub
Private Sub Timer1_Timer()
Call Form_Load
End Sub
Achei aqui mas nem testei, dá uma olhada.
Option Explicit
Private Const TH32CS_SNAPPROCESS As Long = 2
Private Const MAX_PATH As Long = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib [Ô]kernel32[Ô] (ByVal lFlags As Long, _
ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib [Ô]kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib [Ô]kernel32[Ô] (ByVal hSnapShot As Long, _
typProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib [Ô]kernel32[Ô] (ByVal hPass As Long)
Dim strPath As String
Public Function AppIsRunning(ByVal AppName As String) As Boolean
Dim Process As PROCESSENTRY32
Dim hSnapShot As Long
Dim r As Long
AppName = LCase$(AppName)
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot <> -1 Then
Process.dwSize = Len(Process)
r = Process32First(hSnapShot, Process)
Do While r
If LCase$(Left$(Process.szExeFile, InStr(1, Process.szExeFile, vbNullChar) - 1)) = AppName Then
AppIsRunning = True
r = False
End If
r = Process32Next(hSnapShot, Process)
Loop
CloseHandle hSnapShot
End If
End Function
Private Sub Form_Load()
App.TaskVisible = False
strProcessoAtivo = fncLeIni([Ô]Parametros[Ô], [Ô]Processo[Ô])
If strProcessoAtivo = [Ô]SIM[Ô] Then
strPath = App.Path & [Ô]\[Ô]
If AppIsRunning([Ô]PROCESSOATIVO.EXE[Ô]) = False Then
WinExec strPath & [Ô]PROCESS_A_SER_EXECUTADO.EXE[Ô], 10
End If
Else
Exit Sub
End If
End Sub
Private Sub Timer1_Timer()
Call Form_Load
End Sub
Tópico encerrado , respostas não são mais permitidas