FECHAR EXECUTAVEL ATRAVES DE OUTRO EXECUTAVEL

F001E 09/11/2010 16:29:00
#357012
Boa Tarde a Todos...
Aguém poderia me ajudar...é o Seguinte..Meu Sistema tem 5 Módulos onde cada Módulo é aberto atraves de 1 Modulo Principal...Hoje se eu Fechar o .exe do Módulo Principal, os outro Módulos ficam Abertos...
Teria como, se eu Fechar o Módulo Principal, fechar tambem os outros Módulos abertos, no casos os Outros .exe..???

Se alguem souber....
ASHKATCHUP 09/11/2010 17:06:52
#357015
Resposta escolhida
Há duas maneiras:

Enviando comando de fechar


Option Explicit
[ô]
Private Const WM_CLOSE As Long = &H10
[ô]
Private Declare Function FindWindow Lib [Ô]user32[Ô] Alias [Ô]FindWindowA[Ô] (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib [Ô]user32[Ô] Alias [Ô]PostMessageA[Ô] (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Sub subFechaPrograma(sTituloPrograma As String)
Dim enderecoJanela As Long
[ô]
enderecoJanela = FindWindow(vbNullString, sTituloPrograma)
[ô]
If (enderecoJanela = 0) Then
MsgBox [Ô]Não achou![Ô]
Exit Sub
End If
[ô]
PostMessage enderecoJanela, WM_CLOSE, 0, 0
[ô]
End Sub

Private Sub Form_Load()
subFechaPrograma [Ô]Untitled - Notepad[Ô]
End Sub


Terminando o processo


Option Explicit
[ô]
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_TERMINATE As Long = &H1
[ô]
Private Declare Function FindWindow Lib [Ô]user32[Ô] Alias [Ô]FindWindowA[Ô] (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib [Ô]user32[Ô] (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib [Ô]Kernel32[Ô] (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib [Ô]Kernel32[Ô] (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib [Ô]Kernel32[Ô] (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Sub subTerminaProcesso(sTituloPrograma As String)
Dim enderecoJanela As Long
Dim codigoProcesso As Long
Dim guardaProcesso As Long
[ô]
enderecoJanela = FindWindow(vbNullString, sTituloPrograma)
[ô]
If (enderecoJanela = 0) Then
MsgBox [Ô]Não achou![Ô]
Exit Sub
End If
[ô]
GetWindowThreadProcessId enderecoJanela, codigoProcesso
[ô]
guardaProcesso = OpenProcess( _
SYNCHRONIZE Or PROCESS_TERMINATE, _
ByVal 0&, codigoProcesso)
[ô]
If TerminateProcess(guardaProcesso, 0&) <> 0 Then
MsgBox [Ô]Processo terminado![Ô]
End If
[ô]
CloseHandle guardaProcesso
[ô]
End Sub

Private Sub Form_Load()
subTerminaProcesso [Ô]Untitled - Notepad[Ô]
End Sub
F001E 09/11/2010 17:22:42
#357022
ok ASH...vou testar aki
Tópico encerrado , respostas não são mais permitidas