0

I'm trying to access WMI using COM objects with PHP. The method below works very well with PHP on browser, but I can't make it work when the PHP file compiled as a Windows console application.

    $obj = new COM ( 'winmgmts://localhost/root/CIMV2' );
    $fso = new COM ( "Scripting.FileSystemObject" );    

    $csp = $obj->ExecQuery("Select * from Win32_ComputerSystemProduct");

    foreach ( $csp as $wmi_csp )
    {
        $uuid = $wmi_csp->UUID;
    }

I've tried Bambalam BamCompiler, PHC-Win and Phalanger. Bambalam failed to work, but didn't return any error messages. Phalanger failed to identify "COM Object". I noticed that the required PHP Extension is called "php_com_dotnet.dll". But Phalanger does not come with this extension.

I tried to add it to the extensions library, but Phalanger Extutil fails to make a wrapper for it (note that php_com_dotnet.dll's version I copied to the extensions folder does not match with the other extensions' file version).

How can I use COM object, and with which PHP compiler under Windows? Or how can I make Phalanger to accept required extension?

  • No offence, but if you need to access COM objects from compiled code, it sounds like PHP might be the wrong choice of language. – Simba Sep 15 '15 at 11:31
  • @Simba In this case, I will have to, but thank you. – instant_gravelication Sep 15 '15 at 12:15
  • Doesn't phalanger make the more or less complete .net stack available to your php scripts? That should also include System.Management.ManagementClass and Microsoft.Management.Infrastructure (haven't tried it though) – VolkerK Sep 15 '15 at 12:32
  • @VolkerK you're saying I should access WMI with .NET code in my PHP code? I don't know how to do that yet but it's a good suggestion. Thank you. – instant_gravelication Sep 15 '15 at 13:51
  • Phalanger does not support the COM extension since it features complete .NET interoperability instead. Basically any C# sample of using COM objects from C#, rewritten to PHP syntax, should work. To use WMI, System.Management.ManagementClass and Microsoft.Management.Infrastructure are the best way. – Jakub Míšek Sep 16 '15 at 14:58

0 Answers0