Using COM Class

Discussion about the open-source Phalanger [?] project.

Using COM Class

Postby Antilles » September 13th, 2015, 10:16 pm

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
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm

Re: Using COM Class

Postby Jakub Misek » September 15th, 2015, 2:29 pm

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#.
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2058
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Using COM Class

Postby Antilles » September 19th, 2015, 12:07 am

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.
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm

Re: Using COM Class

Postby Jakub Misek » October 12th, 2015, 8:53 pm

The approach is correct, What is the output ?
Jakub Misek │ DEVSENSE s.r.o. │ Email: jakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2058
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Using COM Class

Postby Antilles » November 2nd, 2015, 2:42 pm

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++;
    }
}
Antilles
 
Posts: 6
Joined: September 13th, 2015, 10:10 pm


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 2 guests

cron

User Control Panel

Login

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests (based on users active over the past 5 minutes)
Most users ever online was 62 on January 7th, 2012, 10:54 pm

Users browsing this forum: No registered users and 2 guests
Phalanger