Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Couple of usefull functions with running Processes

Status
Not open for further replies.

Mike Gagnon

Programmer
Apr 6, 2002
8,067
CA
Here are a couple of functions that might be of use. The first one creates a cursor of the currently running processes, and the second one requires a parameter of the running process you want to kill (This will kill all instances of THAT process). (Note this requires Windows Sripting 5.6 installed, and can only be run on the computer that has the runnning processes)
Code:
FUNCTION enumerateProcess
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
	+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colProcessList = loWMIService.ExecQuery ;
	("Select * from Win32_Process")
Create Cursor Process (Name c(20),Id i,Thread i,pagefile i,pagefault i,workingset c(20))
Index On Name Tag Name
For Each loProcess In colProcessList
	Insert Into Process (Name,Id,Thread,pagefile,pagefault,workingset);
		VALUES (loProcess.Name,loProcess.ProcessID,loProcess.ThreadCount,loProcess.PageFileUsage,;
		loProcess.pagefaults,loProcess.WorkingSetSize)
Next
BROWSE normal

FUNCTION terminateProcess(lcProcess)
lcComputer = "."
loWMIService = Getobject("winmgmts:" ;
	+ "{impersonationLevel=impersonate}!\\" + lcComputer + "\root\cimv2")
colProcessList = loWMIService.ExecQuery ;
	("Select * from Win32_Process")
For Each loProcess In colProcessList
   IF UPPER(loProcess.name) = lcProcess
     loProcess.terminate()
   endif
Next

Note: these will added to an on-growing FAQ.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top