Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill process using PID 1

Status
Not open for further replies.

keithf01

Programmer
Jun 24, 2002
13
0
0
US
Can someone provide some sample code on how to kill a running process using the PID?
I already have a function to determine if the process is running and return the PID.

This is for when a process has crashed and is still running in the background. I have an automated program that downloads new versions of code that the user can run. They have to shut down the application client to download the latest version so the DLL will register. But if a process is running in the background due to the application client crashing it will not register the dll. The safest way I believe is to kill any applicaions that are still running.

Thanks,
Keith
keithf@avxus.com
 
Code:
Declare Public Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long

Declare Public Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Public Const PROCESS_ALL_ACCESS = &H1F0FFF
'__________________________

Public Sub sKillServer(Byval lngProcID As Long)

  '--- Kills a running process

  '--- Parameter
  '    lngProcID: the id of the process to kill

  Dim lngRtn As Long
  DimlngProc As Long

  lngProc = OpenProcess(PROCESS_ALL_ACCESS, Clng(0), lngProcID)
  lngRtn = TerminateProcess(lngProc, Clng(0))

End Sub

Paul Bent
Northwind IT Systems
 
Thanks paulbent.
I appreciate it.

Keithf01
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top