`wmic` deprecated and removed in recent Windows versions
Hi there,
While testing our software which uses react/dns v1.13.0 on a fresh Windows Installation (Windows 11 24H2, 26100.2605), I encountered the following error:
PS C:\...> expose
'wmic' is not recognized as an internal or external command, operable program or batch file.
[2024-12-16 11:13:45] production.WARNING: preg_match_all(): Passing null to parameter #2 ($subject) of type string is deprecated in phar://....phar/vendor/react/dns/src/Config/Config.php on line 128
This is probably because Microsoft deprecated WMIC a few years ago and removed it in recent Windows 10/11 versions: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic
My workaround is manually re-installing WMIC as described here: https://techcommunity.microsoft.com/blog/windows-itpro-blog/how-to-install-wmic-feature-on-demand-on-windows-11/4189530
Just wanted to give you a heads-up, as this issue might occur more frequently now that WMIC is no longer included by default.
More information
Used reactphp packages:
› composer why react/dns
react/socket v1.16.0 requires react/dns (^1.13)
› composer why react/socket
react/http v1.11.0 requires react/socket (^1.16)
Let me know if I can provide more details!
@mechelon Thanks for the detailed report and making us aware of this deprecation in Windows. I agree that this is something we should look into as it would likely affect more users over time.
Here's a quick link dump after doing some research:
- WMIC deprecation suggest using WMI cmdlet: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmic -> https://learn.microsoft.com/en-us/powershell/scripting/learn/ps101/07-working-with-wmi
- Workaround using WMIC like mentioned: https://techcommunity.microsoft.com/blog/windows-itpro-blog/how-to-install-wmic-feature-on-demand-on-windows-11/4189530
- https://vnetwise.wordpress.com/2013/10/14/howto-obtain-dns-information-from-nics-via-powershell/
- Original implementation using WMIC in #94 and #95
- Using COM to access WMI: https://www.php.net/manual/en/class.com.php
- https://serverfault.com/questions/84291/how-does-windows-decide-which-dns-server-to-use-when-resolving-names
- https://superuser.com/questions/969171/multihomed-windows-10-dns-resolution-timeouts
- https://github.com/amphp/dns/pull/115
As a result, it looks like using a powershell command like Get-DnsClientServerAddress | Select-Object -ExpandProperty ServerAddresses would be the preferred solution afaict. I've spent some hours on this research, but note that personally I'm not a regular Windows user myself.
I suppose we're happy to accept PRs that implement support for this or if you need this for a commercial project and you want to help sponsor this feature, feel free to reach out and I'm happy to take a look. Other than that, as much as I'd love to work on this myself, there are currently no immediate plans to build this from my end (no demand at the moment and more important outstanding issues currently).
We're definitely interested in getting this supported and will get back to this when time allows. Let us know if you want to work on this or if you're interested in sponsoring this :+1: