FECHAR APLICACAO POR CODIGO
Pessoal,
Já vi vários códigos usando o Kill e o TSKill para fechar aplicativos (.exe) abertos no Windows, mas, conhecem alguma rotina que finalize aplicativos e que funcione em ambos Sistemas operacionais?
Vlw
Já vi vários códigos usando o Kill e o TSKill para fechar aplicativos (.exe) abertos no Windows, mas, conhecem alguma rotina que finalize aplicativos e que funcione em ambos Sistemas operacionais?
Vlw
Ambos? Ambos quais?
Windows XP, Vista, 7 e 8.
Tenta isso....
Private Declare Function FindWindow Lib [Ô]user32[Ô] Alias [Ô]FindWindowA[Ô] (ByVal ilClasse As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib [Ô]user32[Ô] (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib [Ô]user32[Ô] (ByVal hwnd As Long) As Long
Private Sub MDIForm_Unload(Cancel As Integer)
Dim vhwnd As Long
vhwnd = FindWindow(vbNullString, [Ô]NomeDaSuaAplicacao[Ô])
Call ShowWindow(vhwnd, 3)
Call SetForegroundWindow(vhwnd)
End Sub
Private Declare Function FindWindow Lib [Ô]user32[Ô] Alias [Ô]FindWindowA[Ô] (ByVal ilClasse As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib [Ô]user32[Ô] (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function SetForegroundWindow Lib [Ô]user32[Ô] (ByVal hwnd As Long) As Long
Private Sub MDIForm_Unload(Cancel As Integer)
Dim vhwnd As Long
vhwnd = FindWindow(vbNullString, [Ô]NomeDaSuaAplicacao[Ô])
Call ShowWindow(vhwnd, 3)
Call SetForegroundWindow(vhwnd)
End Sub
Usei isto:
Public Sub KillProcess(ByVal processName As String)
[ô]---CAPTURA DE ERROR---
On Error GoTo ErrHandler
[ô]----------------------
[ô]---DECLARACIÓN DE VARIABLES---
Dim oWMI
Dim ret
Dim sService
Dim oWMIServices
Dim oWMIService
Dim oServices
Dim oService
Dim servicename
[ô]------------------------------
[ô]--------------------SE OBTIENEN OBJETOS--------------------
Set oWMI = GetObject([Ô]winmgmts:[Ô])
Set oServices = oWMI.InstancesOf([Ô]win32_process[Ô])
[ô]-----------------------------------------------------------
[ô]----------------------BUSCA EL PROCESO---------------------
For Each oService In oServices
servicename = LCase(Trim(CStr(oService.Name) & [Ô][Ô]))
If InStr(1, servicename, _
LCase(processName), vbTextCompare) > 0 Then
ret = oService.Terminate
End If
Next
[ô]-----------------------------------------------------------
[ô]---------SE HACE NADA---------
Set oServices = Nothing
Set oWMI = Nothing
[ô]------------------------------
[ô]---CAPTURA DE ERROR----
ErrHandler:
Err.Clear
[ô]-----------------------
End Sub
Private Sub Command1_Click()
KillProcess ([Ô]Arquivo.exe[Ô])
End Sub
Tópico encerrado , respostas não são mais permitidas