简体   繁体   中英

PSEXEC access denied when using PHP

I want to retrieve the number of processors running in a remote server, from my server. To do so, I check the information using this command line :

C:\Users\Administrator>psexec -accepteula \\remote_computer_name -u remote_computer_name\admin -p my_password cmd /C "set number_of_processors"

And it returns me the result I wanted :

命令行结果

But when I'm trying to retrive the same result using it in PHP script, it says that the access is denied.

PsExec v1.98 - Execute processes remotely Copyright (C) 2001-2010 Mark Russinovich Sysinternals - www.sysinternals.com

Access is denied.

Connecting to remote_computer_name... Starting PsExec service on remote_computer_name... Could not start PsExec service on remote_computer_name: Connecting to remote_computer_name... Starting PsExec service on remote_computer_name...

Here is my PHP script :

<?php
  function executeCmd($cmd,$params,$return)
    {       
      //$resTable = array();
      $resInt = -1;
      exec("$cmd $params",$resTable,$resInt);
      //$resTable=shell_exec($cmd $params);
      //print_r($resTable);
      if($return == 40)// return associative table
        return $resTable;
      if($return == 41)// return int
        return $resInt;
    }

  $cmd    = "psexec";
  $params   = " -accepteula \\\\remote_computer_name -u remote_computer_name\\admin -p password cmd /C \"set number_of_processors\" 2>&1";
  //$res = system($cmd,$params,40);
  $res = executeCmd($cmd,$params,40);

  for($i=0;$i<count($res);$i++)
  {
    print_r($res[$i]);
    echo "</br>";
  }
?>

I am using the same script on another pair of server, and it is working really well. What did I miss ?

Finally found the answer ! I only add the -h arguments to my command line.

-h If the target system is Vista or higher, has the process run with the account's elevated token, if available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM