Getting Command line that started a ProcessID (win32/VBA(VBS?))

Given a process ID, I wanted to know the command line that launched it. Eventually I want to code this up in MFC/VC6, but for now I mocked it up in VBA (say yuck, but the WMI interface is quite simple compared to C/C++ and win32/MFC):

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = 16132")
For Each objProcess in colItems
 Wscript.Echo "Process: " & objProcess.CommandLine & " Process ID: " & objProcess.ProcessID
Next

 Put your own PID in place of 16132

This file should be given an extension .vbs. Double click on it to get a dialog box, or run from the command line with cscript to get console output. Tested and working with Win10. 

This is the first VBA script I've ever written, but it seems like it's the right tool for the task. 

Obligatory Old New Thing Reference(s):


(this is a good reason to mock up the WMI query first, since you might not get what you want).


(not his actual title)

Raymond is a goldmine of info, and his (pretty old) book is hilarious to old Win32 programmers like myself. It's a literal crime that Microsoft migrated his blog to their new platform, breaking all the old links and deleting all the blog comments in the process. 

Comments

Email me

Name

Email *

Message *

Popular posts from this blog

Panasonic TH-42PX75U Plasma TV review: input lag and upscaling tested using the piLagTesterPRO

piLagTester PRO order page

A $5 TV Input Lag tester using a Raspberry Pi Zero