Enumerate Process IDs

  • Thread starter Thread starter Kevin McCartney
  • Start date Start date
K

Kevin McCartney

Hi,
I'm looking to enumerate though all the all the
processes shown in the Task Manager. It would be even
better if I could get the PID of the New Excel Application
that I set up but I don't think that is possible. Anyway
what I'd like to do is get all PIDs before I open new
Excel Object and then after starting Excel enmuerate again
to find the new PID. (I may have an Excel Already open so
using the process Name 'XLMAIN', doesn't help.) I've
looked at EnumProcess, EnumWindows related to
WinAPI 'user32' library but they don't help because they
are all related to C++. Anyway if some has sample Access
VB code which buts the PID numbers to the debug window
this would be a great help.

Best regards
KM
 
Hi,


You could probably do it with WMI. The code list the processes actually
running on the (remote) PC called Elminster (if you have the required
permissions, admin). Note that it is just a SQL statement, in the heart of
the process:

==================================
Public Sub GetAllProcesses()
Dim objs As WbemScripting.SWbemObjectSet
Dim obj As WbemScripting.SWbemObject
Set objs = GetObject("winmgmts:\\Elminster").ExecQuery("SELECT * FROM
Win32_Process")
For Each obj In objs
Debug.Print obj.Name & ", " & obj.processID & ", " &
obj.ExecutablePath
Next obj

End Sub
====================================

System Idle Process, 0,
System, 4,
smss.exe, 760, C:\WINDOWS\System32\smss.exe
csrss.exe, 808,
winlogon.exe, 832, C:\WINDOWS\system32\winlogon.exe
services.exe, 876, C:\WINDOWS\system32\services.exe
lsass.exe, 888, C:\WINDOWS\system32\lsass.exe
....

You need a reference to "Microsoft WMI Scripting v1.2 Library", and the doc
(what tables are available, what are the fields name) is available in the
WMI SDK available from MSDN site.

You may also check if you didn't disable COM+ (or DCOM, for remote
processing) if that is required. Be sure to get the latest patch for your OS
if you kept that service alive.



Hoping it may help,
Vanderghast, Access MVP
 
Jumping in here (cos I can't see the original post) - another approach might
be to create the excel process using CreateProcess; then you know the ID,
no?

HTH,
TC
 
Back
Top