FECHAR APLICACAO POR CODIGO

SNNIFFER 12/11/2012 19:36:51
#414074
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
KERPLUNK 12/11/2012 23:51:01
#414079
Ambos? Ambos quais?
SNNIFFER 13/11/2012 09:57:21
#414094
Windows XP, Vista, 7 e 8.
F001E 13/11/2012 15:51:17
#414140
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
SNNIFFER 13/11/2012 19:48:17
#414163
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