vb6 getprocess list processes has ? marks in some processes

Posted on 2005-05-10
Last Modified: 2008-03-17
This code is listing some processes as C:\windows\system32\??xplore.exe

Have been fighting this for months would greatly appreciate a solution!!!

where the heck is it getting the ? marks

Option Explicit
Dim uProcess As PROCESSENTRY32

Global AllCurrentProcs As New Collection
Global AllCurrentProcsPID As New Collection
Global AllCurrentProcsEXE As New Collection
Dim JustEXE As String
Dim I As Long

Public Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) 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 GetModuleFileNameExA Lib "psapi.dll" (ByVal hprocess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Public Declare Function GetProcessImageFileNameA Lib "psapi.dll" (ByVal hprocess As Long, ByVal ModuleName As String, ByVal nSize 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 Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

Public Sub GetProcesses()
   Dim lProcCount     As Long
   Dim lProcPoss      As Long
   Dim lNum           As Long
   Dim ProcessIDs()   As Long
   Dim cbNeeded2      As Long
   Dim NumElements2   As Long
   Dim hModule        As Long
   Dim lRet           As Long
   Dim sModName       As String
   Dim hwndProcess    As Long
   Dim iCounter       As Long

   Const SIZE = 500
   Const PROCESS_VM_READ = 16
   'Clear the Collections
   Set AllCurrentProcs = New Collection
   Set AllCurrentProcsPID = New Collection
   Set AllCurrentProcsEXE = New Collection

   'need to get the array containing the process id's for each process object

   lProcCount = 8
   lProcPoss = 96
   Do While lProcCount <= lProcPoss
       lProcCount = lProcCount * 2
       ReDim ProcessIDs(lProcCount / 4) As Long
       lRet = EnumProcesses(ProcessIDs(1), lProcCount, lProcPoss)
   lNum = lProcPoss / 4
   For iCounter = 1 To lNum
       'Get a handle to the Process
       hwndProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, ProcessIDs(iCounter))
       'Got a Process handle
       If hwndProcess = 0 Then
           GoTo SkipHost
           sModName = Space(SIZE)
           lRet = EnumProcessModules(hwndProcess, hModule, 4, cbNeeded2)
           sModName = Space(SIZE)
           lRet = GetModuleFileNameExA(hwndProcess, hModule, sModName, SIZE)
           sModName = Left(sModName, lRet)

           If sModName = "" Then
               GoTo SkipHost
           End If
           'Lower case it
           sModName = LCase(sModName)
Question by:bluedragon99
    LVL 23

    Accepted Solution

    That's a known defect in GetModuleFileNameEx().

    Fortunately, the defect is well behaved.  

    As far as I know, the \??\ appears only on winlogon.exe and can safely be removed.

    Another one you didn't mention is \SystemRoot\System32\smss.exe.
    The \SystemRoot\ should be erplaced with the return from GetWindowsDirectory().

    The cause?  Unknown outside of an embarrassed MS testing cadre, but likely just old NT code that has hung on to life.

    LVL 1

    Author Comment

    getting this one to C:\windows\system32\??xplore.exe

    what replacement code would you suggest?
    LVL 1

    Author Comment

    LVL 1

    Author Comment

    thanks cookre
    LVL 23

    Expert Comment

    Brain dead me.  I just say the GetModuleFileNameEx() and the ?? and plopped in the known problem.  

    Which OS is giving you the flakey iexplore?  
    Your code worked fine (for iexplore) on my XP box.

    Aside from the ones already mentioned, are you getting any other diddled names?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now