0

I am trying to get the bios serial number in PHP which will be stored as an exe through Exeoutput. Since I was not able to fetch the serial number in exeoutput, but was getting it in browser, I concluded that php files are running under a virtual directory so they cannot access hardware. I also got a suggestion that I should use VBScript to fetch the bios serial number and pass it back to php. My vbscript is as below:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20


arrComputers = Array(".")
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo objItem.IdentifyingNumber
   Next
Next

The calling php code is below:

$WshShell = new COM("WScript.Shell");
$obj = $WshShell->Run("cscript mbs.vbs", 0, true);
var_dump($obj);

On executing vbs from command prompt, I am getting the serial number but when trying to make it work through php, I get only

int(1) printed on web page.

user692942
  • 16,398
  • 7
  • 76
  • 175
ITSagar
  • 673
  • 2
  • 10
  • 29
  • Does the `Run()` function return the response of the script or a boolean value that it executed successfully or unsuccessfully? Perhaps look into [`shell_exec()`](http://php.net/manual/en/function.shell-exec.php) to return the output of the file. – Jaquarh Oct 17 '18 at 08:49
  • From the Wscript Reference - *"The Run method **returns an integer**. The Run method starts a program running in a new Windows process. You can have your script wait for the program to finish execution before continuing. This allows you to run scripts and programs synchronously. Environment variables within the argument strCommand are automatically expanded."*. - Its working as designed. – user692942 Oct 17 '18 at 09:02
  • 1
    Possible duplicate of [php execute a background process](https://stackoverflow.com/questions/45953/php-execute-a-background-process) – user692942 Oct 17 '18 at 09:05
  • +1 for Lankymart's comment - you appear to be capturing the success/fail state of the Run() instead of its output. – Jacob M. Oct 17 '18 at 16:41

0 Answers0