Class: Total::Windows

Inherits:
Object
  • Object
show all
Defined in:
lib/total/windows.rb

Overview

Windows specifics.

Instance Method Summary collapse

Instance Method Details

#memoryInteger

Note:

This method requires at least one of the Windows utilities (wmic, powershell.exe, or systeminfo) to be available in the system PATH

Detects the total physical memory available on Windows systems.

This method attempts to determine the system’s total RAM using multiple detection strategies to ensure compatibility across different Windows environments and configurations.

Detection methods (tried in order):

  1. wmic: Windows Management Instrumentation Command-line tool

    • Most reliable on traditional Windows installations

    • Uses: ‘wmic computersystem get TotalPhysicalMemory /value`

  2. PowerShell: Windows PowerShell with WMI queries

    • Available on Windows 7+ and MSYS2 environments

    • Uses: ‘Get-WmiObject -Class Win32_ComputerSystem`

  3. systeminfo: Built-in Windows system information utility

    • Fallback method for restricted environments

    • Parses output to extract memory information in MB/GB format

Examples:

Typical usage

windows = Total::Windows.new
total_memory = windows.memory
puts "Total RAM: #{total_memory / (1024**3)} GB"

Returns:

  • (Integer)

    the total amount of physical memory in bytes

Raises:

  • (CantDetect)

    if all detection methods fail or are unavailable



41
42
43
44
# File 'lib/total/windows.rb', line 41

def memory
  try_wmic || try_powershell || try_systeminfo ||
    raise(CantDetect, 'Can\'t detect memory size via wmic, PowerShell, or systeminfo')
end