【问题标题】:Run the powershell script from client machine从客户端计算机运行 powershell 脚本
【发布时间】:2020-06-05 21:38:29
【问题描述】:

我需要在客户端单击按钮时从客户端计算机运行 powershell 脚本,使用 XAMPP 托管网站并将所有必需的文件放在 htdocs 文件夹中,

<form action="site.php" method="post"> 
  <input type="submit" name="getprocess" class="btn btn-default" value="Prototype"/> 
</form> </li>

<?php

if(array_key_exists('getprocess', $_POST)) { 
  GetProcess(); 
} 

function GetProcess() { 
  echo Shell_Exec ('powershell.exe -executionpolicy bypass -NoProfile -File ".\myscript.ps1"');
  //echo Shell_Exec ('powershell.exe -executionpolicy bypass -NoProfile -Command "Get-Process | ConvertTo-Html"');
}

但是如果我们从客户端单击原型按钮,脚本正在网络服务器上运行,如果需要修改任何内容以使脚本直接从客户端计算机运行,请建议我

【问题讨论】:

  • 简短的回答,你不能从一个网站。那将是一个巨大的安全漏洞。你可以提供一些东西让他们下载然后执行,但希望大多数人甚至不会考虑这样做。

标签: javascript php html powershell xampp


【解决方案1】:

您无法从网站打开客户端上的脚本。那将是一个巨大的安全漏洞!

您可以这样做:

使用 PowerShell 命令“Invoke-Command”在客户端上从服务器执行脚本。更多在这里:https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7

【讨论】:

    【解决方案2】:

    这可能会有所帮助 我们使用 exec 命令执行 R 文件如下

    $invoirment_vars = 'export R_LIBS="/usr/lib64/R/library"; export R_LIBS_USER="/usr/lib64/R/library"; export PATH=$PATH:/usr/bin/;';
    
    $rfile = 'abc.R';
    $rdir = '/var/www/domainnam.com/htdocs/rdir';
    $exe_command = "cd $rdir && Rscript " . $rfile;
    
    exec($invoirment_vars . $exe_command);
    

    所以您也可以尝试根据您的系统发送环境变量

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      • 2014-07-26
      • 2019-11-27
      • 2014-01-01
      相关资源
      最近更新 更多