Page 1 of 1

Using COM Class

PostPosted: September 13th, 2015, 10:16 pm
by Antilles
Hello,

I've been trying to access WMI data on my computer using PHP. My scripts works fine until being compiled by Phalanger; which returns following error message upon running:

"Error: Class 'COM' not found in myfile.php, on line x column y"

This is the method I've been using WMI access:

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

$ddrive = $obj->ExecQuery("Select * from Win32_DiskDrive");

foreach ( $ddrive as $wmi_DiskDrive ) {
$sys = $wmi_DiskDrive->SystemName;
}


How can I use this method to access WMI after this code is compiled?

Thank you

Re: Using COM Class

PostPosted: September 15th, 2015, 2:29 pm
by Jakub Misek
Hi,

COM extension is not supported by Phalanger.

You can use .NET objects directly instead of accessing them through COM wrapper. You can see an example of using WMI in C#.

Re: Using COM Class

PostPosted: September 19th, 2015, 12:07 am
by Antilles
Thank you Jakub. I do not know to program in C#, so I've been doing a lot of trial&error lately. I could get some output out of WMI, but I cannot advance any further at this point. Here's my code so far:

Code: Select all
   $obj = new Management\ManagementObjectSearcher("root\\CIMV2",  "SELECT * FROM Win32_DiskDrive");

        foreach($obj->Get() as $temp) {
     
        var_dump(get_object_vars($temp)); 
        }


I also tried this:

Code: Select all
$query = new Management\SelectQuery("Win32_LogicalDisk");
        $searcher = new Management\ManagementObjectSearcher($query);

        var_dump(get_object_vars($searcher->Get())); 


I can't use the output I'm getting as I didn't work with PHP OOP before, as well. So I'm stuck at this point. Can you provide more specific help ? Because only option I'm left is doing some more trial & error at this point.

Re: Using COM Class

PostPosted: October 12th, 2015, 8:53 pm
by Jakub Misek
The approach is correct, What is the output ?

Re: Using COM Class

PostPosted: November 2nd, 2015, 2:42 pm
by Antilles
Sorry, I waited a reply for a week, in the meantime I tried to figure it out myself. I handled it the way below. I used variable $prop to read necessary data.

Code: Select all
$operatingSrc = new Management\ManagementObjectSearcher("root\\CIMV2",  "SELECT * FROM Win32_OperatingSystem");


$i = 1;

foreach($operatingSrc->Get() as $temp) {
    foreach($temp->Properties as $prop) {
        $i++;
    }
}