Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Const MAX_PATH As Integer = 260
'** OpenHandle Constants.
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_READ = 16
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SYNCHRONIZE = &H100000
'** WaitForSingleObject Return Values.
Public Const WAIT_FAILED = &HFFFFFFFF
Public Const WAIT_OBJECT_0 = &H0
Public Const WAIT_TIMEOUT = &H102
'** API declarations.
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32.dll" (ByVal hPass As Long)
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Public Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function GetModuleBaseNameA Lib "psapi.dll" (ByVal lngProcessHandle As Long, ByVal lngModuleHandle As Long, ByVal strModuleName As String, ByVal lngSize As Long) As Long
Public Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Function GetProcessHandle(strName As String) As Long
'This Function accepts the name of the EXE (i.e. SomeProgram.exe) and scans
'the process list for it. When it is found, the Process ID is returned. If
'it is not found, then the function returns 0.
Dim lngProcessID() As Long
Dim lngCB As Long
Dim lngCBNeeded As Long
Dim lngRetCode As Long
Dim lngLoop As Long
Dim lngProcessHandle As Long
Dim strModuleName As String
Dim strTemp() As String
Dim lngModules(1 To 200) As Long
Dim lngCbNeeded2 As Long
Dim intTemp As Integer
'** Get the current list of running Processes IDs
'******************************************************************************
lngCB = 8
lngCBNeeded = 96
Do While lngCB <= lngCBNeeded
lngCB = lngCB * 2
ReDim lngProcessIDs(lngCB / 4) As Long
lngRetCode = EnumProcesses(lngProcessIDs(1), lngCB, lngCBNeeded)
If lngRetCode = 0 Then
MsgBox Err.LastDllError
Exit Do
End If
Loop
'******************************************************************************
'** Get the name of the Base Module in each Process Space.
'** NOTE : If you wanted to, you could also use the GetModuleBaseNameA API
'** to get every DLL and OCX loaded in the process space.
'******************************************************************************
For lngLoop = 1 To lngCBNeeded / 4
'Get a handle to the Process
lngProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, lngProcessIDs(lngLoop))
'Got a Process handle
If lngProcessHandle <> 0 Then
'Get an array of the module handles for the specified
'process
lngRetCode = EnumProcessModules(lngProcessHandle, lngModules(1), 200, lngCbNeeded2)
'If the Module Array is retrieved, Get the ModuleFileName
If lngRetCode <> 0 Then
strModuleName = Space(MAX_PATH)
lngRetCode = GetModuleBaseNameA(lngProcessHandle, lngModules(1), strModuleName, 500)
ReDim Preserve strTemp(intTemp)
strTemp(intTemp) = Trim$(strModuleName)
'** Check to see if the current process is the target process.
If UCase$(Trim$(strModuleName)) = UCase$(Trim$(strName & Chr$(0))) Then
GetProcessHandle = lngProcessIDs(lngLoop)
Exit For
End If
intTemp = intTemp + 1
End If
End If
Next lngLoop
'******************************************************************************
End Function
[code]
Here is module 2:
[code]
'****************************
'For this module to work correctly, you must also inclue
'modGetProcessHandle.bas into your project
Option Explicit
'** OpenHandle Desired Access Constants.
Private Const PROCESS_TERMINATE = 1
'** Required APIs to terminate other functions.
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_ALL_ACCESS = &H1F0FFF
Public Function KillRunningProgram(EXEname As String) As Long
Dim ProcHand As Long
Dim PIDToKill As Long
Dim lResult As Long
ProcHand = GetProcessHandle(EXEname)
If ProcHand = 0 Then
KillRunningProgram = 0
Exit Function
End If
PIDToKill = OpenProcess(PROCESS_TERMINATE, 0, ProcHand)
KillRunningProgram = TerminateProcess(PIDToKill, 0)
End Function
[code]
You call it like this:
[code]
Dim RetValue As Long
RetValue = KillRunningProgram("Notepad.exe")