Created
December 31, 2024 14:56
-
-
Save soeminnminn/ebc6306a873fdbc38bef3541ead9b254 to your computer and use it in GitHub Desktop.
battery report for windows 10 and 11.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function php_exec( $cmd ){ | |
if( function_exists('exec') ){ | |
$output = array(); | |
$return_var = 0; | |
exec($cmd, $output, $return_var); | |
return implode( " ", array_values($output) ); | |
}else if( function_exists('shell_exec') ){ | |
ob_start(); | |
$output = shell_exec($cmd); | |
ob_end_clean(); | |
return $output; | |
}else if( function_exists('system') ){ | |
$return_var = 0; | |
return system($cmd, $return_var); | |
}else if( function_exists('passthru') ){ | |
$return_var = 0; | |
ob_start(); | |
passthru($cmd, $return_var); | |
$output = ob_get_contents(); | |
ob_end_clean(); //Use this instead of ob_flush() | |
return $output; | |
}else if( function_exists('proc_open') ){ | |
$proc=proc_open($cmd, | |
array( | |
array("pipe","r"), | |
array("pipe","w"), | |
array("pipe","w") | |
), | |
$pipes); | |
return stream_get_contents($pipes[1]); | |
}else{ | |
return "@PHP_COMMAND_NOT_SUPPORT"; | |
} | |
} | |
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | |
$cmd = 'powercfg /batteryreport'; | |
$stdres = php_exec($cmd); | |
if (preg_match('/([A-Z]:[^\.]+\.html)\.$/', $stdres, $matches)) { | |
$file = $matches[1]; | |
if (file_exists($file)) { | |
$content= file_get_contents($file); | |
unlink($file); | |
echo $content; | |
die; | |
} | |
} | |
echo $stdres; | |
} else { | |
echo 'This is not Windows PC!'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment