check memory status

This function gives me a error at WIn32API call. Iam using vbscripts. Any idea how to declare win32API  calls

Function GetMemoryStatus()
Dim Mem
Set GetMemoryStatus = Nothing
Set Mem = Win32API.TMemoryStatus
Mem.dwLength = 32
Set GetMemoryStatus = Mem
End Function
Who is Participating?
purplepomegraniteConnect With a Mentor Commented:
In that case you want to query Win32_Process via WMI.

An example of how to actually query it are here:

A description of the class with its properties is here:

You would be interested in the QuotaNonPagedPoolUsage and QuotaPagedPoolUsage properties if you are checking its memory useage.

this is the best site I know
sorry , pasted by mistake to here , please ignore
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

You cannot access API function directly from VBScript as it only support the variant type.  You need a plug-in to be able to access API calls.

The code you have pasted above comes from another site, and they state that it requires the Win32 API plug-in.  Quite what this is or where it comes from I am not sure.  The only reference I found to it is here:

However, I am not sure if that is relevant to VBScript.
ajaypappanAuthor Commented:
purplepomegranite I know i copied from another site but iam asking for a solution how to make it work.

And API calls can be made using extern functions

extern.Declare micInteger, "SetWindowText","User32.dll","",micHwnd, micString
Extern.Declare micInteger,"GetMemoryStatus","kernel32.dll","GetMemoryStatus",micInteger
What is an extern function?  It is not VBScript as far as I am aware.  Neither of those lines make any sense to me - they are not valid VBScipt without the library of which the extern object is a part.  And I've no idea what library that is.

The solution to get the code you posted above to work is to obtain the Win32 API plug-in, as I said.

VBScript doesn't support API calls in the way VB does.
But then if your question is how to get details about memory from VBScript, there is another answer.

There is code here that will list many details about the memory, from VBScript:
ajaypappanAuthor Commented:
I want to check how much memory a process or application Like IExplorer.exe is using and if it using too much memory close the browser and reopen it..

ajaypappanAuthor Commented:
this is what i did and it works fine..
Public Function winGetMemoryStatus(sTaskName )
On Error Resume Next
Dim objWMIService, objProcess, colProcess
Dim strComputer,  sProcessName,  intSize
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Caption = '" & sTaskName &"'" ,,48)

For Each objProcess in colProcess
          intSize = objProcess.WorkingSetSize/1024
winGetMemoryStatus=  intSize
End function
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.