kill process

E

Esperanza

Hello VB expert,
I need to kill the Excel process because event if all my excel workbooks are
closed the Excel.exe is still running.
I tried the following code found on the internet but I crash at line
Dim lplProcessId as Pointer to Long


Any Idea why ??

Thanks in advance
Esperanza

'--------------------------------------------------------------
Sub KillIt(strCaption$)

Const PROCESS_TERMINATE = &H1& ' Used by KillIt
Dim hProcess As Handle
Dim lProcessId As Long
Dim lplProcessId as Pointer to Long
Dim hWndSPlusAnalysis1 As Long

hWndSPlusAnalysis1 = WFndWnd("+" + strCaption, FW_DEFAULT)

'print "hWndSPlusAnalysis1 = " + trim$(str$(hWndSPlusAnalysis1))

lplProcessId = VarPtr(lProcessId)

GetWindowThreadProcessId(hWndSPlusAnalysis1, lplProcessId)

hProcess = OpenProcess(PROCESS_TERMINATE, False, lProcessId)

TerminateProcess(hProcess, 0)

CloseHandle (hProcess)
' Need a short sleep here to allow SPlus to close before
' trying to delete files it has open:
sleep 1

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top