Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockDevices does not return GUID of the volume on Windows #856

Open
abhinav-maheshwari opened this issue Sep 21, 2023 · 1 comment
Open

Comments

@abhinav-maheshwari
Copy link

GUID of the volume is not returned on Windows in the properties of Block Devices. We need the GUID to be able to mount that volume.

@shoustech
Copy link

This module isn't currently attempting to pull that value but here is a code snipped to do exactly that:

const { exec } = require('child_process');
const { promisify } = require('util');

const execAsync = promisify(exec);

async function runCommand() {
  const command =
    'GWMI -namespace root\\cimv2 -class win32_volume | FL -property DriveLetter, DeviceID';
  const response = await execAsync(command, { shell: 'powershell.exe' });
  if (!response.stderr) {
    return response.stdout;
  } else {
    console.log('Error:', response.stderr);
  }
}

function giveMeJson(windowsOutput) {
  const newResult = [];
  windowsOutput
    .trim()
    .replace(/\r/g, '')
    .split(/\n\s*\n/)
    .map((display, i) => {
      const array = display.split('\n');
      array.map((line) => {
        const entries = line.split(':');
        if (entries.length >= 2) {
          if (!newResult[i]) {
            newResult[i] = {};
          }
          newResult[i][entries[0].trim()] = entries[1].trim();
          return entries;
        }
      });
    });
  return newResult;
}

async function main() {
  console.log(giveMeJson(await runCommand()));
}

main();

Output:

[
  {
    DriveLetter: '',
    DeviceID: '\\\\?\\Volume{a7cc57c3-d84d-47c1-adf1-a51279ae1f9b}\\'
  },
  {
    DriveLetter: 'C',
    DeviceID: '\\\\?\\Volume{a6b89b02-753b-4f4b-91e6-5b3b6e290017}\\'
  },
  {
    DriveLetter: '',
    DeviceID: '\\\\?\\Volume{fc69150b-f4f2-4d37-bc2e-4c3ada835f69}\\'
  },
  {
    DriveLetter: 'N',
    DeviceID: '\\\\?\\Volume{66a9a80f-cff2-46dd-aba1-f8c3d76d6002}\\'
  },
  {
    DriveLetter: '',
    DeviceID: '\\\\?\\Volume{607f2cfb-26ea-4660-9a56-4bf2f99a5365}\\'
  },
  {
    DriveLetter: 'E',
    DeviceID: '\\\\?\\Volume{0a6e00bf-fd3b-11ec-b031-001a7dda7113}\\'
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants