Solved

Need NT 4.0 EnumProcesses() example

Posted on 1998-06-24
3
515 Views
Last Modified: 2008-02-01
I am trying to kill a "hung" application process in NT.  This process is an ActiveX .EXE so it runs independently.  As this process does not have a GUI, I am trying to check to see if it is running and if so, get its process ID using the PSAPI.DLL functions.  I think I have the PSAPI.DLL file itself, but I need an example of how to use this DLL to check for a running process and how to get the process ID.

Thanks,

Shawn Woods
0
Comment
Question by:swoods
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 250 total points
ID: 1464185
0
 

Author Comment

by:swoods
ID: 1464186
clifABB,

Your answer was perfect!  I spent 3 days searching for an example or any documentation without luck before this Knowledgebase article.  Thanks a million!!!  

I'm going to give you the "A" credit anyway for solving my problem so quickly, but I have a small related question for you if you don't mind.  Now that I have the Path and other Process Information, what is the best way to kill the "hung" process(es)?

Thanks again for your help!

Shawn Woods
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1464187
This is what I have learned:

Apparently you can end a process by calling ExitProcess().  To call this, you must pass an ExitCode which is retrieved with GetExitCodeProcess()
From what I gather, the following code will kill the process specified:

Declare Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)
Declare Function GetExitCodeProcess Lib "kernel32" Alias "GetExitCodeProcess" (ByVal hProcess As Long, lpExitCode As Long) As Long
Public Sub KillProcess(lProcess As Long)
  Dim lExitCode As Long
  Dim lRes As Long

  lRes = GetExitCodeProcess(lProcess, lExitCode)
  ExitProcess lExitCode
End Sub

I'm not sure if this will work, but it seems like it should.

For more information on processes, check out the info at MSDNOnline:
http://premium.microsoft.com/msdn/library/sdkdoc/prothred_7mib.htm
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question