free memory 
Author Message
 free memory

How can I know the free memory (free RAM) at a moment with
a JScript.


Tue, 24 Aug 2004 23:19:10 GMT  
 free memory

Quote:

> How can I know the free memory (free RAM) at a moment with
> a JScript.

One way to do it:

//////////////////////////////////////////////////////////////////////
//    File: Mem.js

var oShell = new ActiveXObject("WScript.Shell");

if (!isCScript()||(WScript.Arguments.Length!=1)) {
    showUsage();
    WScript.Quit();

Quote:
}

var sHost = WScript.Arguments(0);   //  sHost can be Host Name or IP address
showMemInfo(sHost);

//////////////////////////////////////////////////////////////////////

function showMemInfo(sHost) {

    try {
        var oOSset = GetObject("winmgmts:{impersonationLevel=impersonate}//" + sHost).InstancesOf ("Win32_OperatingSystem")
    } catch(e) {
        switch (e.Number) {
            case 462 :
                //  The remote server machine does not exist or is unavailable
                WScript.Echo ("Host is not available.");
                return;
            case 429 :
                //  ActiveX component can't create object
                WScript.Echo ("Host is missing WMI capabilities.");
                return;
            case -2147217405 :
                //  Lacking admim permissions to connect to host
                WScript.Echo("Not enough permissions to connect to this host.");
                return;
            default :
                //  Whatever else the cause may be...
                WScript.Echo(e.description);
                return;
        }
    }

    var oEnm_1 = new Enumerator(oOSset);
    var oEnm_2;

    WScript.Echo();
    WScript.Echo("Host: " + sHost);

    for (; !oEnm_1.atEnd(); oEnm_1.moveNext()) {
        oEnm_2 = new Enumerator(oEnm_1.item().Properties_);

        for (; !oEnm_2.atEnd(); oEnm_2.moveNext()) {
            //  Pick only memory related properties (ignore the rest):
            switch (oEnm_2.item().Name) {
                case "TotalVisibleMemorySize" :
                    WScript.Echo("\tTotal RAM         -> " + Math.round(oEnm_2.item().Value/1024) + "\tMB");
                    continue;
                case "FreePhysicalMemory" :
                    WScript.Echo("\tFree RAM          -> " + Math.round(oEnm_2.item().Value/1024) + "\tMB");
                    continue;
                case "FreeSpaceInPagingFiles" :
                    WScript.Echo("\tFree in page file -> " + Math.round(oEnm_2.item().Value/1024) + "\tMB");
                    continue;
                case "TotalVirtualMemorySize" :
                    WScript.Echo("\tTotal virtual mem -> " + Math.round(oEnm_2.item().Value/1024) + "\tMB");
                    continue;

            }
        }
    }

Quote:
}

function isCScript() { return (/cscript.exe$/i).test(WScript.FullName); }

function showUsage() {
    var sMsg = "Syntax: \tC:\\>CScript //nologo " + WScript.ScriptName + " IP\r\n";
    sMsg += "        \t(must be run by 'CScript.exe')";
    WScript.Echo(sMsg);

Quote:
}

// Branimir


Wed, 25 Aug 2004 11:24:38 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Free memory detection with asp

2. Does VBScript free memory on END FUNCTION?

3. free memory in client !?

4. are 465K free memory ok for an expensive printer

5. How to free memory in Jscript/DHTML

6. How to get Free/Available Memory

7. FREE CASH GET FREE 100 STAMPS FOR FREE MONEY

8. Memory leaks ? No collection of no longer used memory ?

9. Excel in Memory after display in browser

10. "not enough memory......"

11. Out of memory error (800a0007) inside MTS object

 

 
Powered by phpBB® Forum Software