Giter Club home page Giter Club logo

wmic's Introduction

wmic

Wrapper around the Windows WMIC interface for Node.js.

Example

var wmic = require('wmic');

// equivalent of 'wmic nic get list'
wmic.get_list('nic', function(err, nics) {
  // console.log(err || nics);
})

Usage

wmic.get_value(section, value, conditions, callback)

Returns a single value from wmic, for example to get the hostname:

wmic.get_value('computersystem', 'name', null, function(err, value) {
  console.log(value) // Your Hostname
})

wmic.get_values(section, value, conditions, callback)

Returns an array of values from wmic, for example to list hard drives:

wmic.get_values('logicaldisk', 'name, volumename', null, function(err, values) {
  console.dir(values) // An array of disks
})

Credits

Written by Tomas Pollak, with the help of contributors.

Small print

(c) Fork Ltd, MIT licensed.

wmic's People

Contributors

jonaskgandersson avatar marcelcremer avatar saschl avatar thorn0 avatar tomas avatar totalgrifflock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wmic's Issues

Multiple WMIC Requests are executed serially

Hello everyone,

when you try to execute many wmic commands, they are processed serially instead of parallel. Thats because the async.queue has no amount of workers specified (default 1). Maybe it should be set to 100 or something to make the request asynchronously.

The affected line is line 233 in index.js.

Best Regards
Marcel

Reliance on cmd.exe

We use a package in our corporate environment which imports your wmic module to execute the wmic command. However in our environment normal users (i.e. non admins) do not have access to the command prompt - it's disabled by policy. This breaks the wmic module as you use child_process.spawn to start wmic.exe in a full shell (cmd /c) rather than using child_process.execfile which would run the exe directly. Is this intentional due to the amount of output data the wmic command can generate? Or does the wmic.exe process require a full cmd shell in order to work properly?

Does not work with fields containing spaces

I have a problem with the library parsing the results of the wmic command
From the command line I can execute this

wmic useraccount get name,sid,fullname

and I get this back

wmic useraccount get name,fullname,sid
FullName        Name                SID
                Administrator       S-1-5-21-3391238925-54190052-3516795850-500
                DefaultAccount      S-1-5-21-3391238925-54190052-3516795850-503
                Guest               S-1-5-21-3391238925-54190052-3516795850-501
Kiosk           kioskUser0          S-1-5-21-3391238925-54190052-3516795850-1002
Roger Hardiman  roger               S-1-5-21-3391238925-54190052-3516795850-1001
                WDAGUtilityAccount  S-1-5-21-3391238925-54190052-3516795850-504

However when I try this with the wmic library I get this output

[
{"FullName":"","Name        Name":"Administ","SID":"S-1-5-21-3391238925-54190052-3516795850-500"},
{"FullName":"","Name        Name":"DefaultA","SID":"S-1-5-21-3391238925-54190052-3516795850-503"},
{"FullName":"","Name        Name":"Guest","SID":"S-1-5-21-3391238925-54190052-3516795850-501"},
{"FullName":"Kiosk","Name        Name":"k           kioskUse","SID":"S-1-5-21-3391238925-54190052-3516795850-1002"},
{"FullName":"Roger Hardiman","Name        Name":"r Hardiman  roger","SID":"S-1-5-21-3391238925-54190052-3516795850-1001"},
{"FullName":"","Name        Name":"WDAGUtil","SID":"S-1-5-21-3391238925-54190052-3516795850-504"}]

My Javascript is

var wmic = require('./index.js');

wmic.get_values('useraccount', 'name,fullname,sid', null, function(err, values) {
  console.dir(values) // An array of disks
  console.log(JSON.stringify(values))
})

I assume there is a bug when parsing the text returned from the wmic command

What is the api?

I tried running this code

wmic.run('logicaldisk get name', function() {
  console.log(wmic.pid)
});

And this?

wmic.run('logicaldisk get name')

But no return value, command is working because I uncommented the console.logs for stdout and stderr events for spawn.

Better description in package.json

Hello,

I found this useful module on npm, but I couldn't find the url of repo at the page.
And also the license you declared in readme.md and package.json do not match.

It will be appreciated if you would update the package.json.

Thanks!

Bad detection of console encoding on some Korean machines

Hi,

The expected output of the chcp command on Windows machines is like:
Active code page: 850

In that case the following code correctly provides the actual code page:
var codePage = stdout.replace(/\D/g, '');

But on some machines the output of chcp contains an error code, for instance:
"활占쏙옙 占쌘듸옙 占쏙옙占쏙옙占쏙옙: 949\r\n[0x7FFAF4317EA0] ANOMALY: meaningless REX prefix used"

In such a case the codePage becomes incorrect:
"9490743170"
instead of the expected "949"

This ends up later with errors like
Encoding not recognized: 'cp9490743170' ... (in iconv-lite actually)

May I suggest to retrieve the encoding differently, like:
var codePage = stdout.replace(/\n.*$/, '').replace(/\D/g, '');
or
var codePage = (/\d+/.exec(stdout)||[''])[0];

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.