«

»

Nov 22

Print this Post

Get Free Physical Memory Free/ Virtual Memory/ Number Of Processes by WMI

How to find OS details/ physical memory/ virtual memory/ processor information of local or remote machine?

 

WMI Script:

VBScript:

arrComputers = Array(“localhost”)
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo “==========================================”
WScript.Echo “Computer: ” & strComputer
WScript.Echo “==========================================”

Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\CIMV2″)
Set colItems = objWMIService.ExecQuery( _
“SELECT * FROM Win32_OperatingSystem”,,48)
For Each objItem in colItems
Wscript.Echo “———————————–”
Wscript.Echo “Win32_OperatingSystem instance”
Wscript.Echo “———————————–”
Wscript.Echo “BuildNumber: ” & objItem.BuildNumber
Wscript.Echo “Caption: ” & objItem.Caption
Wscript.Echo “CSName: ” & objItem.CSName
Wscript.Echo “FreePhysicalMemory: ” & objItem.FreePhysicalMemory
Wscript.Echo “FreeSpaceInPagingFiles: ” & objItem.FreeSpaceInPagingFiles
Wscript.Echo “FreeVirtualMemory: ” & objItem.FreeVirtualMemory
Wscript.Echo “Manufacturer: ” & objItem.Manufacturer
Wscript.Echo “MaxNumberOfProcesses: ” & objItem.MaxNumberOfProcesses
Wscript.Echo “MaxProcessMemorySize: ” & objItem.MaxProcessMemorySize
Wscript.Echo “NumberOfProcesses: ” & objItem.NumberOfProcesses
Wscript.Echo “SerialNumber: ” & objItem.SerialNumber
Wscript.Echo “TotalVirtualMemorySize: ” & objItem.TotalVirtualMemorySize
Wscript.Echo “TotalVisibleMemorySize: ” & objItem.TotalVisibleMemorySize
Next
Next

 

C#

using System;
using System.Management;
using System.Windows.Forms;

namespace SampleProgram
{
public class SampleQuery
{
public static void Main()
{
try
{
string[] arrComputers = {“localhost”};
foreach (string strComputer in arrComputers)
{
Console.WriteLine(“==========================================”);
Console.WriteLine(“Computer: ” + strComputer);
Console.WriteLine(“==========================================”);

ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
“\\\\” + strComputer + “\\root\\CIMV2″,
“SELECT * FROM Win32_OperatingSystem”);

foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine(“———————————–”);
Console.WriteLine(“Win32_OperatingSystem instance”);
Console.WriteLine(“———————————–”);
Console.WriteLine(“BuildNumber: {0}”, queryObj["BuildNumber"]);
Console.WriteLine(“Caption: {0}”, queryObj["Caption"]);
Console.WriteLine(“CSName: {0}”, queryObj["CSName"]);
Console.WriteLine(“FreePhysicalMemory: {0}”, queryObj["FreePhysicalMemory"]);
Console.WriteLine(“FreeSpaceInPagingFiles: {0}”, queryObj["FreeSpaceInPagingFiles"]);
Console.WriteLine(“FreeVirtualMemory: {0}”, queryObj["FreeVirtualMemory"]);
Console.WriteLine(“Manufacturer: {0}”, queryObj["Manufacturer"]);
Console.WriteLine(“MaxNumberOfProcesses: {0}”, queryObj["MaxNumberOfProcesses"]);
Console.WriteLine(“MaxProcessMemorySize: {0}”, queryObj["MaxProcessMemorySize"]);
Console.WriteLine(“NumberOfProcesses: {0}”, queryObj["NumberOfProcesses"]);
Console.WriteLine(“SerialNumber: {0}”, queryObj["SerialNumber"]);
Console.WriteLine(“TotalVirtualMemorySize: {0}”, queryObj["TotalVirtualMemorySize"]);
Console.WriteLine(“TotalVisibleMemorySize: {0}”, queryObj["TotalVisibleMemorySize"]);
}
}
}
catch(ManagementException err)
{
MessageBox.Show(“An error occurred while querying for WMI data: ” + err.Message);
}
}
}
}

Out Put:

==========================================

Computer: localhost
==========================================
———————————–
Win32_OperatingSystem instance
———————————–
BuildNumber: 7601
Caption: Microsoft Windows 7 Enterprise
CSName: Server01
FreePhysicalMemory: 568224
FreeSpaceInPagingFiles: 1072436
FreeVirtualMemory: 1420912
Manufacturer: Microsoft Corporation
MaxNumberOfProcesses: -1
MaxProcessMemorySize: 2097024
NumberOfProcesses: 102
TotalVirtualMemorySize: 4047336
TotalVisibleMemorySize: 2023668

Permanent link to this article: http://www.techxpress.in/get-free-physical-memory-free-virtual-memory-number-of-processes-by-wmi/

Bookmark this page