| View previous topic :: View next topic |
| Author |
Message |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Fri Apr 10, 2009 9:07 pm Post subject: Path of running exe without using LIST MODULES? |
|
|
Ok, I know that I can get the full path of a running process by using LIST TASKLIST and then LIST MODULES. But my problem is that I'm using it within a TIMER loop for some monitoring here, and LIST MODULES spikes the cpu to 100% every time it is run. I can't have my program spiking the cpu out every 0.5 like that. It just does not agree with me at all.
So, does anyone know if there's a way to find out if an exe is running without using LIST MODULES?
What I have is a list of programs with full paths, and I want to check if they are running or not. I only have the program and it's path, no class names, no window id, just name of the exe and it's path. And I want to be sure that the specific program is running, not a copy of it located elsewhere. So I want to monitor for c:\windows\notepad.exe and not c:\program files\nt accessories\notepad.exe Otherwise I'd just use LIST TASKLIST
Is there any api call I can use?
Thanks in advance,
~Garrett _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Apr 11, 2009 3:50 pm Post subject: |
|
|
The only other way I can think of is querying WMI.
I use GadgetX for the WMI query.
I haven't seen a way with native VDS yet.
WMI code:
| Code: | strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Process",,48)
For Each objItem in colItems
Wscript.Echo objItem.ExecutablePath
Next |
This should be easy to convert to GadgetX. If you like, I will convert it when I get home. |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Apr 11, 2009 5:43 pm Post subject: |
|
|
Please. Thanks I was never any good at all in converting stuff to gadget. _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sat Apr 11, 2009 8:11 pm Post subject: |
|
|
For your coding pleasure
Here is an example of getting the process list or a specific process via WMI using GadgetX. This only shows some of the many details you can get about a process using WMI.
| Code: | # This code is based in part on Dragonsphere's Device List via WMI script.
# For more info on GadgetX go to www.dragonsphere.net
# This script requires GadgetX.dll and at minimum VDS 5.x
#
# Author: Michael Andersen aka "Aslan" - Written 20090411@1504
Title Process List VIA WMI
If @Greater(@Name(@SYSINFO(DSVER)),4)
External GadgetX.dll,@SYSINFO(DSVER)
# GadgetX Commands
#DEFINE COMMAND,GadgetX,DEFINE,OLE,Set
# GadgetX Functions
#DEFINE FUNCTION,GadgetX,OLE,Get
Else
Warn This Example uses VDS 5 or above syntax.
Stop
End
# Objects needed to get the process list
Define variable,Object,objWMI
Define variable,Object,objProcesses
Define variable,Object,objProcess
# A collection that will hold the list of processes
Define variable,Collection,colProcesses
# Initialize Ole
Ole Init
# Get the local WMI object
Set objWMI,@Ole(GetObject,NULL,"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
DIALOG CREATE,Get Process List VIA WMI,-1,0,656,243
DIALOG ADD,BUTTON,getbtn,207,20,115,24,Get All Processes
DIALOG ADD,BUTTON,QUIT,207,576,64,24,Quit
DIALOG ADD,TEXT,TEXT1,16,19,97,13,Process List
DIALOG ADD,TABLE,TABLE1,34,19,622,161,Name[180]|Path[200]|CmdLine
DIALOG ADD,BUTTON,SearchExecutable,207,161,125,24,Search Executable
DIALOG ADD,EDIT,exeName,209,304,180,19,<name.exe>
DIALOG SHOW
:evloop
wait event
goto @event()
:QUITBUTTON
:CLOSE
Ole Free,Object,objWMI
Ole UnInit
Exit
:GETBTNBUTTON
List clear,TABLE1
# Query for the Processes
Set objProcesses,@Ole(Call,objWMI,^o,"ExecQuery(^B)",Select * From Win32_Process)
# get the Process collection
Set colProcesses,@Ole(BeginCollection,objProcesses)
# Walk through the collection
While @Ole(Next,objProcess,In,colProcesses)
# Get the name of the Process
%%Name = @Ole(Get,objProcess,"^B",Name)
# Get the Executable Path
%%ExecutablePath = @Ole(Get,objProcess,"^B",ExecutablePath)
# Get the full command line associated with the process
%%CommandLine = @Ole(Get,objProcess,"^B",CommandLine)
List Add,TABLE1,%%Name@Tab()%%ExecutablePath@tab()%%CommandLine
Wend
# Free the collection
Ole Free,Collection,colProcesses
# Free the objProcesses object
Ole Free,Object,objProcesses
goto evloop
:SearchExecutableBUTTON
List clear,TABLE1
%%exeName = @dlgtext(exeName)
If @both(@unequal(%%exeName,),@unequal(%%exeName,<name.exe>))
# Query for the Processes
Set objProcesses,@Ole(Call,objWMI,^o,"ExecQuery(^B)",Select * From Win32_Process Where Name = '%%exeName')
# get the Process collection
Set colProcesses,@Ole(BeginCollection,objProcesses)
# Walk through the collection
While @Ole(Next,objProcess,In,colProcesses)
# Get the name of the Process
%%Name = @Ole(Get,objProcess,"^B",Name)
# Get the Executable Path
%%ExecutablePath = @Ole(Get,objProcess,"^B",ExecutablePath)
# Get the full command line associated with the process
%%CommandLine = @Ole(Get,objProcess,"^B",CommandLine)
List Add,TABLE1,%%Name@Tab()%%ExecutablePath@tab()%%CommandLine
Wend
# Free the collection
Ole Free,Collection,colProcesses
# Free the objProcesses object
Ole Free,Object,objProcesses
Else
Warn Invalid Query!
End
goto evloop |
Enjoy  |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Apr 11, 2009 9:37 pm Post subject: |
|
|
thanks a bunch Aslan  _________________ 'What you do not want done to yourself, do not do to others.' - Confucius (550 b.c. to 479 b.c.) |
|
| Back to top |
|
 |
Aslan Valued Contributor


Joined: 31 May 2001 Posts: 589 Location: Memphis, TN USA
|
Posted: Sun Apr 12, 2009 12:27 am Post subject: |
|
|
NP Garrett
You can get a wealth of info using WMI.
Just the Win32_Process object alone has a bunch of queriable objects.
The List:
Caption
CommandLine
CreationClassName
CreationDate
CSCreationClassName
CSName
Description
ExecutablePath
ExecutionState
Handle
HandleCount
InstallDate
KernelModeTime
MaximumWorkingSetSize
MinimumWorkingSetSize
Name
OSCreationClassName
OSName
OtherOperationCount
OtherTransferCount
PageFaults
PageFileUsage
ParentProcessId
PeakPageFileUsage
PeakVirtualSize
PeakWorkingSetSize
Priority
PrivatePageCount
ProcessId
QuotaNonPagedPoolUsage
QuotaPagedPoolUsage
QuotaPeakNonPagedPoolUsage
QuotaPeakPagedPoolUsage
ReadOperationCount
ReadTransferCount
SessionId
Status
TerminationDate
ThreadCount
UserModeTime
VirtualSize
WindowsVersion
WorkingSetSize
WriteOperationCount
WriteTransferCount |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|