VBScript to check for Memory used by a process on Windows

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
MAlam
Posts: 3
Joined: Wed Jun 13, 2007 1:54 pm

VBScript to check for Memory used by a process on Windows

Post by MAlam »

Hi,
I am new to hostmon so if I am a lil off on some basics please accept my apologies....

I am trying to setup a test (currently using VBScript) to get the memory usage of a specific process from a remote Windows computer. Following is the script

Code: Select all


Option Explicit 
const statusAlive       = "Host is alive:" 
const statusDead        = "No answer:" 
const statusUnknown     = "Unknown:" 
const statusNotResolved = "Unknown host:" 
const statusOk          = "Ok:" 
const statusBad         = "Bad:" 
const statusBadContents = "Bad contents:" 


Dim objWMIService, objProcess, colProcess, WorkingSetSize 
Dim strComputer, strProcess 
strComputer = "192.168.2.2" 
strProcess = "'ThisServer.exe'" 

FUNCTION performtest() 
  WorkingSetSize = "0" 
  
  Set objWMIService = GetObject("winmgmts:" _ 
  & "{impersonationLevel=impersonate}!\\" _ 
  & strComputer & "\root\cimv2") 
  
  Set colProcess = objWMIService.ExecQuery _ 
  ("Select WorkingSetSize from Win32_Process Where Caption = " & strProcess ) 

  For Each objProcess in colProcess 
    WorkingSetSize = objProcess.WorkingSetSize 
  Next 
  IF (WorkingSetSize > 0)  THEN 
     performtest = statusOk & WorkingSetSize 
  ELSE 
     performtest = statusBad & WorkingSetSize 
  END IF 

END FUNCTION
My goal:

a. To get the memory usage in MB by a particular process on a remote machine every 30 secs.
b. Get an alert if this value is above x for say 10 polling intervals.
c. Have the response log to a file with timestamp.

So far I am only able to get the memory used by a process on a local machine.

So my first question is: "How can I pass the credentials to connect to the remote machine"

and then how can I log all the responsess to a file with time stamp. I want to do this so that I can have a graphical output from this data.

Thanks for all your help.

Alam
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

1) I am not sure you need a script. You may use Performance Counter test method (query like \\systemname\Process(processname)\Working Set)
http://www.ks-soft.net/hostmon.eng/mfra ... erfcounter
or WMI test method (query like Select WorkingSetSize from Win32_Process Where Caption = 'processname'). In case of WMI test you will get result in bytes
http://www.ks-soft.net/hostmon.eng/mfra ... ts.htm#wmi

2) Then you may use Connection Manager to provide necessary credentials
http://www.ks-soft.net/hostmon.eng/mfra ... htm#conmgr

3) Logging... well logging is essential function of HostMonitor, you don't need to do anything special for this
http://www.ks-soft.net/hostmon.eng/mframe.htm#logs.htm

Regards
Alex
Post Reply