Solved

PHP, WMI, COM object and getting the array value

Posted on 2011-02-24
3
850 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 27
Be edit-table when I click the edit button (turn into inputs boxes) 7 29
google map tracking website 5 24
two ways encryption with php 3 28
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

773 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