'==========================================================================
'
' NAME: <LoggedRunningProcesses.vbs>
'
' AUTHOR: Ed Wilson , MS
' DATE  : 4/29/2006
'
' COMMENT: <Lists information on running processes on system>
'
'==========================================================================
Option Explicit 
'On Error Resume Next
dim strComputer		'computer to connect to with wmi
dim wmiNS					'wmi namespace
dim wmiQuery			'the wmi query
dim objWMIService	'connection using wmi moniker
dim colItems			'collection of wmi objects
Dim objItem				'individual item in the collection
Dim strProperties 'properties to choose
Dim strValues			'string of wmi values

strComputer = "."
wmiNS = "\root\cimv2"
strProperties = "name,processID,pageFaults,WorkingSetSize"
wmiQuery = "Select " & strProperties & " from win32_process" &_
	" where processID <>0"
	
subText(strProperties)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS)
Set colItems = objWMIService.ExecQuery(wmiQuery)

For Each objItem in colItems
	With objItem
	  strValues = .name & "," & .processID & "," &_
	   .PageFaults & "," & .WorkingSetSize
	End With

subText(strValues)
Next


' **** subs below ****
Sub subText(strIN)
Dim objfso		'the filesystemobject
Dim objfile		'file object
Dim objshell	'wshshell object
Dim strPath		'path to desktop
Dim strFile		'log file name

Const ForAppending = 8
Const createFile = True
strFile = funfix("logProps.csv") 'adds \ to file name

Set objshell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = objshell.SpecialFolders("desktop")
strFile = strPath & strFile
Set objfile = objfso.OpenTextFile(strFile,ForAppending,createFile)
objfile.WriteLine (strIN)
End Sub

Function funfix (strIN)
funfix = "\" & strin
End Function