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

Doesn't work on Windows because "Wmic" removed. #29

Open
altannylmz opened this issue Dec 25, 2021 · 2 comments
Open

Doesn't work on Windows because "Wmic" removed. #29

altannylmz opened this issue Dec 25, 2021 · 2 comments

Comments

@altannylmz
Copy link

Microsoft removed the WMIC tool from Windows 11 Dev builds and this command is not working.

path : node_modules\node-disk-info\src\utils\constants.ts line 9

"wmic logicaldisk get Caption,FreeSpace,Size,VolumeSerialNumber,Description /format:list"

image

I tried to contribute but I have doubts about what to use instead of wmic.

@altannylmz
Copy link
Author

My solution :

getDisksInfo = () =>

new Promise(resolve =>
{
    let os = require('os');
    if (os.platform() === "win32")
    {
        let spawn = require("child_process").spawn,child;

        child = spawn("powershell.exe",[" get-psdrive  -psprovider filesystem | select-object name,used,free | ConvertTo-Json"]);

        child.stdout.on("data", function (data) {

            let res = JSON.parse(data);
            res.forEach( obj => renameKey( obj, 'Name', 'mounted'));
            res.forEach( obj => renameKey( obj, 'Used', 'used'));
            res.forEach( obj => renameKey( obj, 'Free', 'available'));

            for(let i = 0 ; i < res.length ; ++i)
                res[i].mounted = res[i].mounted + ":";

            resolve(res);
        });

    }
    else // other systems
    {
        const nodeDiskInfo = require('node-disk-info');
        nodeDiskInfo.getDiskInfo().then(disks => {
            resolve(disks);
        });
    }
});

function renameKey ( obj, oldKey, newKey ) {
    obj[newKey] = obj[oldKey];
    delete obj[oldKey];
}

@alyzhao
Copy link

alyzhao commented Feb 22, 2022

in my windows, Get-PSDrive -PSProvider FileSystem command executed return empty Used and Free

PS C:\WINDOWS\system32> Get-PSDrive -PSProvider FileSystem

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
C                                      FileSystem    C:\                                               WINDOWS\system32

dscalzi added a commit to dscalzi/helios-core that referenced this issue Aug 21, 2023
WMIC is deprecated and/or removed and node-disk-info is abandoned.
cristiammercado/node-disk-info#29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants