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

'WMIC' no longer exists in windows 11 24H2 #446

Open
wilianmaique opened this issue Feb 28, 2025 · 4 comments
Open

'WMIC' no longer exists in windows 11 24H2 #446

wilianmaique opened this issue Feb 28, 2025 · 4 comments

Comments

@wilianmaique
Copy link

Pulse Version

last

Laravel Version

last

PHP Version

8.4

Livewire Version

last

Database Driver & Version

mysql

Description

trying to use command: php artisan pulse:check, returns error: 'wmic' is not recognized as an internal command. from what i read, it was removed from windows 11

i use windows as a dev environment, but in production i use linux....

Steps To Reproduce

...

@jessarcher
Copy link
Member

We're currently using wmic to get the CPU and memory usage for the "Servers" card on Windows (this was introduced in #165)

@wilianmaique or @kohenkatz are you aware of any alternative ways of getting this information without wmic?

Note that it's possible to customize how CPU and memory usage are determined with the following:

\Laravel\Pulse\Recorders\Servers::detectCpuUsing(fn () => /* CPU percentage as an integer */);

\Laravel\Pulse\Recorders\Servers::detectMemoryUsing(fn () => [
    'total' => /* Total memory in megabytes as an integer */,
    'used' => /* Used memory in megabytes as an integer */
]);

@wilianmaique
Copy link
Author

We're currently using wmic to get the CPU and memory usage for the "Servers" card on Windows (this was introduced in #165)

@wilianmaique or @kohenkatz are you aware of any alternative ways of getting this information without wmic?

Note that it's possible to customize how CPU and memory usage are determined with the following:

\Laravel\Pulse\Recorders\Servers::detectCpuUsing(fn () => /* CPU percentage as an integer */);

\Laravel\Pulse\Recorders\Servers::detectMemoryUsing(fn () => [
'total' => /* Total memory in megabytes as an integer /,
'used' => /
Used memory in megabytes as an integer */
]);

I used COM and it worked correctly:

$wmi = new \COM("WinMgmts://");
    $cpus = $wmi->ExecQuery("SELECT LoadPercentage FROM Win32_Processor");

    [$totalCpuLoad, $cpuCount] = 0;

    foreach ($cpus as $cpu) {
      $totalCpuLoad += $cpu->LoadPercentage;
      $cpuCount++;
    }

    $averageCpuLoad = $cpuCount > 0 ? $totalCpuLoad / $cpuCount : 0;

    $memory = $wmi->ExecQuery("SELECT TotalVisibleMemorySize, FreePhysicalMemory FROM Win32_OperatingSystem");
    $mem = $memory->ItemIndex(0);

    $totalMemory = $mem->TotalVisibleMemorySize * 1024;
    $freeMemory = $mem->FreePhysicalMemory * 1024;
    $usedMemory = $totalMemory - $freeMemory;
    $usedPercentage = ($usedMemory / $totalMemory) * 100;

    echo '<pre>';
    print_r([
      'CPU Load (%)' => $averageCpuLoad,
      'Total Memory' => Number::fileSize($totalMemory, precision: 2),
      'Free Memory' => Number::fileSize($freeMemory, precision: 2),
      'Used Memory' => Number::fileSize($usedMemory, precision: 2),
      'Used Memory Percentage (%)' => Number::percentage($usedPercentage, precision: 2)
    ]);
    echo '</pre>';

out:

Array
(
    [CPU Load (%)] => 14
    [Total Memory] => 31.87 GB
    [Free Memory] => 16.19 GB
    [Used Memory] => 15.68 GB
    [Used Memory Percentage (%)] => 49.19%
)

note, you need to enable: extension=com_dotnet in php.ini (this extension is already included)

@kohenkatz
Copy link
Contributor

wmic isn't actually removed from Windows 11, just the executable is disabled by default. You can re-enable it like this (as admin):

DISM /Online /Add-Capability /CapabilityName:WMIC~~~~

That said, switching to the com_dotnet extension is probably a better way forward. I don't have time to do a PR myself at the moment, but it looks like a fairly simple change.

Copy link

github-actions bot commented Mar 3, 2025

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

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