Solved

PHP, WMI, COM object and getting the array value

Posted on 2011-02-24
3
853 Views
Last Modified: 2012-05-11
This code

      define ( 'CPU_NAME', '.' );

      $obj = new COM ( 'winmgmts:{impersonationLevel=impersonate}//' . CPU_NAME . '/root/cimv2' );

      if ( is_object ( $obj ) )
      {
            $process = $obj->execquery ( "SELECT * FROM Win32_BIOS" );

            if ( $process->count > 0 )
            {
                  foreach($process as $row){
                  	echo"BIOS: $row->bioscharacteristics<br />";
                  }
            }
            else
            {
                  echo 'error';
            }

            $obj = null;
      }
      else
      {
            echo 'no object';
      }

Open in new window


produces an error

Catchable fatal error: Object of class variant could not be converted to string in C:\xampp\htdocs\aa\index.php on line 71

I'm aware of the WMI classes and the property value of the BIOS characteristics as it is an array of integers separated with "," - or maybe just string value of integers with ",". Most of the Win32 classes does not give this error (Win32_Account for example). Caould you guide me how to deal with these kind of situations ?
0
Comment
Question by:Lukasz Chmielewski
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Learnctx earned 500 total points
ID: 34977708
I have never done anything with PHP, but as far as doing this in VBScript or PowerShell I would usually join this particular property array into a single string and then use it.
[string]::Join(",",(GWMI -Q "SELECT bioscharacteristics FROM Win32_BIOS").BiosCharacteristics)

Open in new window

I'm assuming in PHP you can do something similar?
0
 
LVL 27

Author Comment

by:Lukasz Chmielewski
ID: 34977721
Thanks for response, I'll try to convert it to PHP and get back to you.
0
 
LVL 27

Author Closing Comment

by:Lukasz Chmielewski
ID: 34987917
Well, partially. Made me code some more to finally get the value into an array.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question