Solved

PHP, WMI, COM object and getting the array value

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

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now