 | |  | | | ¿Quién está en línea? Actualmente hay 52 invitados, 0 miembro(s) conectado(s).
Eres un usuario anónimo. Puedes registrarte aquí | |  | |  |
|  |
 |
|
 |
| |
Cerrar proceso utilizando el nombre del EXE
Posted on Monday, 18 July a las 16:13:12 by galegre
Cómo matar un proceso si se conoce el nombre del archivo EXE. Un método más seguro para cerrar aplicaciones en vez de utilizar el título de su ventana principal.
Este ejemplo muestra cómo cerrar un proceso con la API de Windows, y utilizando el nombre del EXE a cerrar.
Código: Crear un proyecto nuevo de Visual Basic y en el Form1 colocar un TextBox y CommandButton, luego pegar el siguiente código.
Option Explicit
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" _
(ByVal lFlags As Long, ByVal 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 Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
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 Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
ByVal uExitCode 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 Const PROCESS_TERMINATE = &H1
Private Const PROCESS_CREATE_THREAD = &H2
Private Const PROCESS_VM_OPERATION = &H8
Private Const PROCESS_VM_READ = &H10
Private Const PROCESS_VM_WRITE = &H20
Private Const PROCESS_DUP_HANDLE = &H40
Private Const PROCESS_CREATE_PROCESS = &H80
Private Const PROCESS_SET_QUOTA = &H100
Private Const PROCESS_SET_INFORMATION = &H200
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Private Sub Command1_Click()
Dim hSnapShot As Long, uProceso As PROCESSENTRY32
Dim res As Long, dwIDProceso As Long
Dim hProceso As Long, Resultado As Long
dwIDProceso = -1
hSnapShot = CreateToolhelpSnapshot(2&, 0&)
If hSnapShot <> 0 Then
uProceso.dwSize = Len(uProceso)
res = ProcessFirst(hSnapShot, uProceso)
Do While res
If Left$(uProceso.szExeFile, InStr(uProceso.szExeFile, Chr$(0)) - 1) = LCase(Text1.Text) Then
'Si se encuentra el proceso, se guarda su ID.
dwIDProceso = uProceso.th32ProcessID
Exit Do
End If
res = ProcessNext(hSnapShot, uProceso)
Loop
Call CloseHandle(hSnapShot)
End If
'Si el proceso no está abierto...
If dwIDProceso = -1 Then
MsgBox "El proceso """ & LCase(Text1.Text) & """ no está abierto"
Else
hProceso = OpenProcess(PROCESS_TERMINATE, True, dwIDProceso)
Resultado = TerminateProcess(hProceso, 99)
CloseHandle hProceso
'Si se cerró correctamente...
If Resultado <> 0 Then
MsgBox "El proceso """ & LCase(Text1.Text) & """ ha sido cerrado correctamente."
Else
MsgBox "El proceso """ & LCase(Text1.Text) & """ no pudo ser cerrado."
End If
End If
End Sub
Ejecutar la aplicación y escribir en el cuadro de texto el nombre del EXE a cerrar y luego pulsar el botón.
|
|
 |
|
 |
| |
 | |  | | | Votos del Artículo Puntuación Promedio: 4.14 votos: 14

| |  | |  |
|
 |
|
 |
| |
|
| | Los comentarios son propiedad de quien los envió. No somos responsables por su contenido. |
|
|
 |
|
 |
 |
|
 |
| |
No se permiten comentarios Anónimos, Regístrese por favor |
|
 |
|
 |
 |
|
 |
| |
Re: Cerrar proceso utilizando el nombre del EXE (Puntuación 0) por Anonymous el Monday, 05 June a las 12:08:31 | | Se podria realizar esta aplicacion para terminar procesos en ordenadores remotos? |
|
|
 |
|
 |
 |
|
 |
| |
Re: Cerrar proceso utilizando el nombre del EXE (Puntuación 1) por karensol el Tuesday, 29 April a las 13:11:11 (Información del Usuario | Enviar un Mensaje) | hola
trabajo en visual basic .net la linea
If Left$(uProceso.szExeFile, InStr(uProceso.szExeFile, Chr$(0)) - 1) = LCase(Text1.Text) Then
como podria cambiarla,es la unica que no puedo arreglar tengo problemas con Left$
i conoces alguna soluion , estaria agradecida |
|
|
 |
|
 |
 |
|
 |
| |
Re: Cerrar proceso utilizando el nombre del EXE (Puntuación 1) por foxin el Wednesday, 01 February a las 03:08:10 (Información del Usuario | Enviar un Mensaje) | | Durability and professional in the Beats by dre [www.idrebeats.com] field of portable audio is very important, portable stereo headset relatively lightweight and easy to be damaged; professional headsets use and moves around, but also easy to cross the line and pull off, requiring headphones made ??very strong, and easy maintenance and replacement parts. Another is Monster Headphones [www.idrebeats.com] associated with the durability to withstand the power, Beats Sale Online [www.idrebeats.com] small power you can push the headset is very loud, when there is more than the power to withstand the possibility of damage to the headset, the headset under Beats by Dre Studio [www.idrebeats.com] the general civil power less than 100mW, 100mW-professional headset 1000mW. The voice coil of high impedance headphones strong resistance, unlike the low-impedance headphones as sensitive to the voice coil to the power Beats Solo HD [www.idrebeats.com] changes, and more durable. |
|
|
 |
|
 |
 |
|
 |
| |
Moncler Down Jackets (Puntuación 1) por afra99 el Monday, 16 January a las 19:22:38 (Información del Usuario | Enviar un Mensaje) | | Get close with our popular Discount Moncler Jackets [www.newmoncler-officialwebsite.com],you will find lots of amazing about these excellent Moncler Down Jackets [www.newmoncler-officialwebsite.com].Everyone has the right to fight for what you want,i think you absolutely would be interested with our New Moncler Jackets [www.newmoncler-officialwebsite.com],which are lauched on Moncler Online Store [www.newmoncler-officialwebsite.com].There is nothing can be hesitate for you to buy a piece of such gorgeous New Moncler Coats [www.newmoncler-officialwebsite.com].Buy some pieces of Moncler Down Coats [www.newmoncler-officialwebsite.com],you will go through with the wonderful daily time. |
|
|
 |
|
 |
 |
|
 |
| |
Re: Cerrar proceso utilizando el nombre del EXE (Puntuación 1) por monifa08 el Tuesday, 27 December a las 01:28:47 (Información del Usuario | Enviar un Mensaje) | | Sexy,stylish,beautiful and confident,unique design,comfortable to wear, Christian Louboutin Booties [www.louboutinstosale.com] always bring you so much surprise and charms,you are hard to resist its temptation.If you like,welcome to login our cheap louboutin shoes sale store [www.louboutinstosale.com] to have a look and choose your favorite style. |
|
|
 |
|
 |
 |
|
 |
| |
monclers online (Puntuación 1) por afra99 el Friday, 16 December a las 02:06:16 (Información del Usuario | Enviar un Mensaje) | | Let me share these stylish cheap down jackets [www.monclersjackets4sale.com] with you. These sweaters can be worn by all men to attend all kinds of moncler jackets [www.monclersjackets4sale.com] occasions.So wherever you go, wear these moncler vest [www.monclersjackets4sale.com] sweater should be perfect. Now, our monclers online [www.monclersjackets4sale.com] online shop will sale all products with the biggest discount moncler outlet [www.monclersjackets4sale.com]. The high quality and stylish design will let you rest assure to moncler wiki [www.monclersjackets4sale.com] purchase. |
|
|
 |
|
 |
 |
|
 |
| |
moncler online (Puntuación 1) por afra99 el Friday, 16 December a las 02:06:19 (Información del Usuario | Enviar un Mensaje) | | These discounted moncler coats [www.downjackets-cheapsale.com] are elegant design for women, the colors are so attractive, I think women are all love doudoune moncler [www.downjackets-cheapsale.com] such things. Visit our moncler online [www.downjackets-cheapsale.com] and take one surprises go home. Trust me, you will be have a wonderful moncler jackets [www.downjackets-cheapsale.com] and warm winter this year. If you want to know more information about discount moncler jackets [www.downjackets-cheapsale.com], please come to our online shop now. Here besides mocler down jackets [www.downjackets-cheapsale.com], other styles products are also very stylish and unique. |
|
|
 |
|
 |
 |
|
 |
| |
canada goose jakke (Puntuación 1) por canadagoose el Tuesday, 01 November a las 03:26:49 (Información del Usuario | Enviar un Mensaje) | Canada Goose [www.canadagoosejakke2012.net] parka clothes, using a excellent brand name clothes, which was founded in Canada. Canada Goose Jakke [www.canadagoosejakke2012.net] within of the outfits latest market in winter.These design jacket to preserve the look at of person.All the people love this brand and would like to choose it as their must-have item in winter. If you are not so considerably concerned about style, you can opt for normal winter coats that give warmth. Like Canada Goose Kvinders [www.canadagoosejakke2012.net] and Canada Goose Mænd [www.canadagoosejakke2012.net].
New Style belstaff [www.belstaff-sito-ufficiale.com] sale online, Authentic belstaff outlet [www.belstaff-outlet.de] store,Discount Belstaff Jacktets, Sale Belstaff Jackets, Belstaff coats, Belstaff bags and so on with free shipping. |
|
|
 |
|
 |
|