Skip to content

Commit

Permalink
Added some sanity checks to remove any errors wmic might produce, yet…
Browse files Browse the repository at this point in the history
… still work
  • Loading branch information
grilled-cheese committed Oct 15, 2014
1 parent f1c1d79 commit c8358a9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions wmi.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ function display_help() {
exit($execstatus);
}

// Chomp any errors that wmic might have thrown, but still worked
$classindex = -1;
for($i=0;$i<count($wmiout);$i++)
{
if(0 === strpos($wmiout[$i], 'CLASS: '))
{
$classindex = $i;
break;
}
}
// Abort is the wmi output isn't normally structured
if($classindex == -1)
{
echo "WMI Class Chomp Failed!\nWMI Client Output: ".implode("\n", $wmiout)."\n";
exit(1);
}
for($i=0;$i<$classindex;$i++)
{
unset($wmiout[$i]);
}
// reindex the array output
$wmiout = array_values($wmiout);

$wmi_count = count($wmiout); // count the number of lines returned from wmic, saves recouting later

if ($wmi_count > 0) {
Expand Down

0 comments on commit c8358a9

Please sign in to comment.