How to use the wmic.get_values function in wmic

To help you get started, we’ve selected a few wmic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prey / prey-node-client / lib / agent / providers / indicators / windows.js View on Github external
exports.get_battery_status = function(cb) {

  var keys = 'Availability,BatteryStatus,EstimatedChargeRemaining,EstimatedRunTime';

  var get_state = function(num) {
    if (num == 1)
      return 'discharging';
    else if (num == 2 || num == 3)
      return 'charged';
    else if (num == 5)
      return 'critical';
    else
      return 'charging';
  }

  wmic.get_values('Path Win32_Battery', keys, null, function(err, obj) {
    if (err) return cb(err);

    if (obj.Availability == '11')
      return cb(new Error('No battery found.'))

    var data = {
      percentage_remaining: parseInt(obj.EstimatedChargeRemaining),
      state: get_state(parseInt(obj.BatteryStatus)),
      time_remaining: obj.EstimatedRunTime || 'unknown'
    }

    cb(null, data);
  });

};

wmic

Wrapper around the WMIC Windows command interface.

MIT
Latest version published 2 years ago

Package Health Score

47 / 100
Full package analysis