Microsoft KB Archive/242416

= How To Enumerate 16-bit Tasks on Window NT Using Visual Basic =

Article ID: 242416

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition, when used with:
 * Microsoft Windows NT 4.0
 * Microsoft Visual Basic 6.0 Learning Edition, when used with:
 * Microsoft Windows NT 4.0
 * Microsoft Visual Basic 5.0 Professional Edition, when used with:
 * Microsoft Windows NT 4.0
 * Microsoft Visual Basic 6.0 Professional Edition, when used with:
 * Microsoft Windows NT 4.0
 * Microsoft Visual Basic 5.0 Enterprise Edition, when used with:
 * Microsoft Windows NT 4.0
 * Microsoft Visual Basic 6.0 Enterprise Edition, when used with:
 * Microsoft Windows NT 4.0

-



This article was previously published under Q242416



SUMMARY
There may be times when it is necessary to enumerate all of the 16-bit tasks that are running on a Windows NT system. To do this you use the VDMEnumProcessWOW and VDMEnumTaskWOWEx API functions. The MORE INFORMATION section to follow demonstrates how to use these functions within Visual Basic. Note, that it is also necessary to use call back functions to enumerate the 16-bit processes. If you are unfamiliar with the use of callback functions from within Visual Basic, see the article mentioned in the REFERENCES section of this article.



Steps to Create the Example
 Start a new Standard EXE project in Visual Basic. Form1 is created by default. Add one CommandButton to the form. Set the forms AutoReDraw property to True. Select Project from the Menu and add a new module to the project. Module1 is created by default.  Copy the following code into the Code window of Module1: Option Explicit

Declare Function VDMEnumProcessWOW Lib "VDMDBG.dll" _ (ByVal fp As Long, lparam As Long) As Integer

Declare Function VDMEnumTaskWOWEx Lib "VDMDBG.dll " _ (dwProcessId As Long, ByVal fp As Long, lparam As Long) As Integer

Declare Function lstrcpy Lib "kernel32" _ (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long

Public Function PROCESSENUMPROC _ (ByVal dwProcessId As Long, ByVal dwAttributes As Long, _ lpUserDefined As Long) As Boolean Form1.Cls Form1.Print "dwProcessId: " & dwProcessId Form1.Print "dwAttributes: " & dwAttributes & vbCrLf ' Pass the Process ID to this next function to enumerate that Process. Call VDMEnumTaskWOWEx(ByVal dwProcessId, AddressOf TASKENUMPROCEX, 0)

End Function

Public Function TASKENUMPROCEX _ (ByVal dwThreadId As Long, ByVal hMod16 As Long, _ ByVal hTask16 As Long, ByVal pszModName As Long, _ ByVal pszFileName As Long, lpUserDefined As Long) As Boolean

' Print Enumerated task of the 16bit process Form1.Print "dwThreadId: " & dwThreadId & vbCrLf & _ "hMod16: " & hMod16 & vbCrLf & "hTask16: " & hTask16 & vbCrLf & _ "pszModName: " & PointerToString(pszModName) & vbCrLf & _ "pszFileName: " & PointerToString(pszFileName) & vbCrLf & _ "lpUserDefined: " & lpUserDefined & vbCrLf ' Return value is false until there are no more tasks to enumerate. End Function

Private Function PointerToString(lPtr As Long) As String Dim sTemp As String * 255, Retval As Long ' Parse String Values returned from function call.

Retval = lstrcpy(sTemp, lPtr) If (InStr(1, sTemp, Chr(0)) = 0) Then PointerToString = "" Else PointerToString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1) End If End Function   Copy the following code into the Code window of Form1: Private Sub Command1_Click

Dim Retval As Long ' Call VDMEnumProcessWOW to beging the enumeration Retval = VDMEnumProcessWOW(AddressOf PROCESSENUMPROC, 0)

End Sub  Save the Project and then press F5 to run the project. The enumerated processes will list on the form.</li></ol>

<div class="references_section">