MeshAgent icon indicating copy to clipboard operation
MeshAgent copied to clipboard

Changed WMIC to non-deprecated alternatives

Open HuFlungDu opened this issue 1 year ago • 1 comments

This is a companion pull request with: https://github.com/Ylianst/MeshCentral/pull/6320

Fixes #254

In this PR, I modified the JS module code containing the wmic changes and the one C file with wmic hardcoded in it. I did not recompile the modules, as I'm not sure of the procedure for doing so, though I did compile them locally for testing, they just didn't come out with all the comments and ifdefs and whatnot.

HuFlungDu avatar Aug 12 '24 17:08 HuFlungDu

this is another reason we cant switch yet to using powershell https://github.com/Ylianst/MeshAgent/issues/256 it seems to spawn powershells over and over again!

si458 avatar Aug 29 '24 10:08 si458

just done a quick compile/test and can confirm this fixes the uncaught: 'cannot read property \x27split\x27 of null' error also! the error stems from the util-language.js file!!!

si458 avatar Nov 01 '24 20:11 si458

I was looking into the source code; is it possible to do this with modules/win-wmi.js?

Looks like it's mostly a query library, so it doesn't handle everything, but it should get rid of a lot of the powershell invocations.

HuFlungDu avatar Nov 01 '24 20:11 HuFlungDu

@HuFlungDu erm possibly yes! as we already use it inside the meshcore and a few other files

ret = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_ComputerSystem', ['Name', 'Domain'])[0];
...
values = require('win-wmi').query('ROOT\\CIMV2', "SELECT * FROM Win32_PhysicalMemory");
...
v = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume');

i wont merge this just yet but it does give us ideas to look into using the win-wmi instead tho!

si458 avatar Nov 01 '24 20:11 si458

ok so i can confirm the win-wmi works! and even fixes the crashing on startup! replacement section of code below for util-language.js inside the getCurrent function

// On windows we will use WMI to get the LCID. 
if (process.platform == 'win32') {
  var tokens = require('win-wmi').query('ROOT\\CIMV2', 'SELECT OSLanguage FROM Win32_OperatingSystem', ['OSLanguage']);
  if (tokens[0]) {
    // Convert LCID to language string
    return (toLang(tokens[0]['OSLanguage'].toString()));
  } else {
    // fallback to en-us to avoid crashing
    return ("en-us");
  }
}

so my plan will be next week to take this PR and the PR from meshcentral and replace everything using wmic with win-wmi! unless u want to beat me to it!

si458 avatar Nov 01 '24 22:11 si458

ok so ive done commits to fix the split issue on startup and also replace the wmic service with net commands others will follow!

si458 avatar Nov 03 '24 15:11 si458

i cannot thank you enough for the help! ive also learnt how to build the polyfills and its working a treat now! commits below https://github.com/Ylianst/MeshAgent/commit/105da7dbfae9b32d5be67bbe12b1dee5fda400c9 https://github.com/Ylianst/MeshAgent/commit/435bccd1eb335b2d54ad2057d8c40a477201df51 https://github.com/Ylianst/MeshAgent/commit/d08c5ceb711d8c1e21ffb4b5f8f58f3f5e39bcf0

si458 avatar Nov 04 '24 15:11 si458

Looks awesome, thanks Simon! And thanks for the info about how to build the modules and such, that'll make any changes we need much easier.

HuFlungDu avatar Nov 04 '24 16:11 HuFlungDu

@HuFlungDu u can now build the agent now from the repo code and it fully supports 24h2 :) I'm gunna deploy a build tonight to my production server, update a few agents and see how it goes I only have 2 24h2 devices the rest are windows 10 or 11 23h2 so will be fun hehe

si458 avatar Nov 04 '24 16:11 si458