Skip to content

Commit

Permalink
another wmic replacement
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Smith <[email protected]>
  • Loading branch information
si458 committed Nov 4, 2024
1 parent 435bccd commit 105da7d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 623 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,5 @@ ASALocalRun/

# Klocwork
.klocwork/

*.o
4 changes: 2 additions & 2 deletions microscript/ILibDuktape_Commit.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is auto-generated, any edits may be overwritten
#define SOURCE_COMMIT_DATE "2023-Apr-14 13:29:41-0700"
#define SOURCE_COMMIT_HASH "ca52306f87407a122fac70723bfa025b9c422ae6"
#define SOURCE_COMMIT_DATE "2024-Nov-3 15:40:18+0000"
#define SOURCE_COMMIT_HASH "435bccd1eb335b2d54ad2057d8c40a477201df51"
2 changes: 1 addition & 1 deletion microscript/ILibDuktape_Polyfills.c

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions modules/identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,32 +560,34 @@ function macos_identifiers()

function win_chassisType()
{
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'SystemEnclosure', 'get', 'ChassisTypes']);
// needs to be replaced with win-wmi but due to bug in win-wmi it doesnt handle arrays correctly
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], {});
if (child == null) { return ([]); }
child.descriptorMetadata = 'process-manager';
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('Get-CimInstance Win32_SystemEnclosure| Select-Object -ExpandProperty ChassisTypes\r\n');
child.stdin.write('exit\r\n');
child.waitExit();

try
{
var tok = child.stdout.str.split('{')[1].split('}')[0];
var val = tok.split(',')[0];
return (parseInt(val));
}
catch (e)
{
try {
return (parseInt(child.stdout.str));
} catch (e) {
return (2); // unknown
}
}

function win_systemType()
{
var CSV = '/FORMAT:"' + require('util-language').wmicXslPath + 'csv"';
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'ComputerSystem', 'get', 'PCSystemType', CSV]);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.waitExit();

return (parseInt(child.stdout.str.trim().split(',').pop()));
try {
var tokens = require('win-wmi').query('ROOT\\CIMV2', 'SELECT PCSystemType FROM Win32_ComputerSystem', ['PCSystemType']);
if (tokens[0]) {
return (parseInt(tokens[0]['PCSystemType']));
} else {
return (parseInt(1)); // default is desktop
}
} catch (ex) {
return (parseInt(1)); // default is desktop
}
}

function win_formFactor(chassistype)
Expand Down
Loading

0 comments on commit 105da7d

Please sign in to comment.