Solved

check memory status

Posted on 2008-06-11
10
612 Views
Last Modified: 2012-06-27
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
Win32API.GlobalMemoryStatus(Mem)
Set GetMemoryStatus = Mem
End Function
0
Comment
Question by:ajaypappan
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:elimesika
ID: 21763890
HI

this is the best site I know

http://www.cetus-links.org/oo_c_plus_plus.html
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21763901
sorry , pasted by mistake to here , please ignore
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21763950
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: http://www.orchardsoft.com/4dapps/win32api.htm

However, I am not sure if that is relevant to VBScript.
0
 
LVL 7

Expert Comment

by:TRobinJames
ID: 21764336
0
 
LVL 3

Author Comment

by:ajaypappan
ID: 21769580
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
or
Extern.Declare micInteger,"GetMemoryStatus","kernel32.dll","GetMemoryStatus",micInteger
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21769846
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.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21769953
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: http://tlepsh.blogspot.com/2007/08/vbscript-listing-memory-config.html
0
 
LVL 3

Author Comment

by:ajaypappan
ID: 21770971
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..

0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 250 total points
ID: 21771312
In that case you want to query Win32_Process via WMI.

An example of how to actually query it are here: http://www.computerperformance.co.uk/vbscript/wmi_process.htm

A description of the class with its properties is here: http://msdn.microsoft.com/en-us/library/aa394372(VS.85).aspx

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

Author Comment

by:ajaypappan
ID: 21772078
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
Next
winGetMemoryStatus=  intSize
End function

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_23214344.html
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now