border
VB 6
 
 
  #1 (permalink)  
Antiguo 20-07-2008, 07:52:18
Gran Participación en el Foro
 
Registrado: nov 2004
Posts: 215
Créditos: 8.850
mcrex1 Valoración +2
Predeterminado cerrar la ejecución de un exe

¿ Como puedo saber si se está ejecutando una aplicación y que al cerrar mi proyecto cierre tambien este exe si se está ejecutando?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Responder Con Cita
  #2 (permalink)  
Antiguo 20-07-2008, 17:40:43
Avatar de seba123neo
Moderador
 
Registrado: nov 2007
Ubicación: Argentina
Posts: 799
Créditos: 5.926
seba123neo Valoración +2
Predeterminado Re: cerrar la ejecución de un exe

Hola,aca tenes un codigo para cerrar un proceso por su nombre de ejecutable.

Código:
Option Explicit

Private Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

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 * 260
End Type
Private Type OSVERSIONINFO
   dwOSVersionInfoSize As Long
   dwMajorVersion As Long
   dwMinorVersion As Long
   dwBuildNumber As Long
   dwPlatformId As Long
   szCSDVersion As String * 128
End Type
Private Const PROCESS_ALL_ACCESS = 0
Private Const TH32CS_SNAPPROCESS As Long = 2&

Private Const WINNT As Integer = 2
Private Const WIN98 As Integer = 1

Public KillAppReturn As Boolean
Public Function getVersion() As Integer
 Dim udtOSInfo As OSVERSIONINFO
 Dim intRetVal As Integer
       
   With udtOSInfo
       .dwOSVersionInfoSize = 148
       .szCSDVersion = Space$(128)
   End With
   
   intRetVal = GetVersionExA(udtOSInfo)
 
   getVersion = udtOSInfo.dwPlatformId
End Function

Public Function Killapp(myName As String)
Select Case getVersion()
Case WIN98
Killapp9X (myName)
Case WINNT
KillappNT (myName)
End Select
End Function

Private Function KillappNT(myName As String)
   Dim uProcess As PROCESSENTRY32
   Dim rProcessFound As Long
   Dim hSnapshot As Long
   Dim szExename As String
   Dim exitCode As Long
   Dim myProcess As Long
   Dim AppKill As Boolean
   Dim appCount As Integer
   Dim I As Integer
   On Local Error GoTo Finish
   appCount = 0
   uProcess.dwSize = Len(uProcess)
   hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
   rProcessFound = ProcessFirst(hSnapshot, uProcess)
   Do While rProcessFound
       I = InStr(1, uProcess.szExeFile, Chr(0))
       szExename = LCase$(Left$(uProcess.szExeFile, I - 1))
       If Right$(szExename, Len(myName)) = LCase$(myName) Then
           KillAppReturn = True
           appCount = appCount + 1
           myProcess = OpenProcess(1&, -1&, uProcess.th32ProcessID)
           AppKill = TerminateProcess(myProcess, 0&)
           Call CloseHandle(myProcess)
       End If
       rProcessFound = ProcessNext(hSnapshot, uProcess)
   Loop
   Call CloseHandle(hSnapshot)
Finish:
KillAppReturn = False
End Function

Private Function Killapp9X(myName As String)
   Dim uProcess As PROCESSENTRY32
   Dim rProcessFound As Long
   Dim hSnapshot As Long
   Dim szExename As String
   Dim exitCode As Long
   Dim myProcess As Long
   Dim AppKill As Boolean
   Dim appCount As Integer
   Dim I As Integer
   On Local Error GoTo Finish
   appCount = 0
   uProcess.dwSize = Len(uProcess)
   hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
   rProcessFound = ProcessFirst(hSnapshot, uProcess)
   Do While rProcessFound
       I = InStr(1, uProcess.szExeFile, Chr(0))
       szExename = LCase$(Left$(uProcess.szExeFile, I - 1))
       If Right$(szExename, Len(myName)) = LCase$(myName) Then
           KillAppReturn = True
           appCount = appCount + 1
           myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
           AppKill = TerminateProcess(myProcess, exitCode)
           Call CloseHandle(myProcess)
       End If
       rProcessFound = ProcessNext(hSnapshot, uProcess)
   Loop
   Call CloseHandle(hSnapshot)
Finish:
KillAppReturn = False
End Function

Private Sub Form_Load()
Killapp "CALC.exe"
End Sub
en este caso cierra la calculadora de windows

saludos.
__________________
Todos somos ignorantes; lo que pasa es que no todos ignoramos las mismas cosas - Albert Einstein
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Responder Con Cita
Respuesta


Herramientas

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Trackbacks are habilitado
Pingbacks are habilitado
Refbacks are habilitado



La franja horaria es GMT. Ahora son las 19:38:03.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
© VB-MUNDO CO. Todos los derechos reservados
Tutoriales Premium | Juegos Online 


right

Programacion, vb 6, visual basic, foro programacion

Inactive Reminders By Icora Web Design