doulian8485 2017-02-14 12:44
浏览 154
已采纳

使用PHP时,PSEXEC访问被拒绝

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 \emote_computer_name -u remote_computer_name\admin -p my_password cmd /C "set number_of_processors"

And it returns me the result I wanted :

Command Line Result

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 \\\emote_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 ?

  • 写回答

1条回答 默认 最新

  • dongtaijue1578 2017-03-06 10:48
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化