Using COM Class
5 posts
• Page 1 of 1
Using COM Class
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
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
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#.
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. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Using COM Class
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:
I also tried this:
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.
- 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
The approach is correct, What is the output ?
Jakub Misek │ DEVSENSE s.r.o. | @misekjakub │ jakub@devsense.com │
-
Jakub Misek - Posts: 2092
- Joined: January 4th, 2012, 2:42 pm
- Location: Prague
Re: Using COM Class
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
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests