简体   繁体   English

在网络共享文件夹上使用 IIS 从 PHP 调用 PowerShell

[英]Calling PowerShell from PHP using IIS on network shared folders

I have a simple PHP page that calls a simple PowerShell script.我有一个简单的 PHP 页面,它调用一个简单的 PowerShell 脚本。

test.php测试文件

<?php
    $runCMD = "powershell.exe -NoProfile -ExecutionPolicy Bypass -File teste.ps1 2>&1";
    exec($runCMD,$out,$ret);
    if ($ret != 0) {
        echo "Could not run PowerShell.";
    } else {
        echo implode("\n",$out);
    }
?>

test.ps1测试.ps1

Write-Host "Just testing!"

When both files are placed in c:\\inetpub\\wwwroot, everything works fine.当两个文件都放在 c:\\inetpub\\wwwroot 中时,一切正常。 However, if I place them in a shared network folder (\\\\myserver\\test, for example) and point IIS to this folder, php still works but it's not able to run the PowerShell script anymore.但是,如果我将它们放在共享网络文件夹(例如 \\\\myserver\\test)中并将 IIS 指向该文件夹,php 仍然可以工作,但无法再运行 PowerShell 脚本。 exec just returns error code 1 and the message "Could not run PowerShell" is printed. exec 仅返回错误代码 1 并打印消息“无法运行 PowerShell”。 I am currently using PHP 7.4.1, IIS 10, Windows Server 2019 and PowerShell 5.1.我目前使用 PHP 7.4.1、IIS 10、Windows Server 2019 和 PowerShell 5.1。

Any ideas on how to solve this?关于如何解决这个问题的任何想法?

App pool identities have very limited access to the local file system (and none outside the local computer).应用程序池标识对本地文件系统的访问非常有限(并且在本地计算机之外没有)。 You will need to modify ACLs on the file system to give the identities the access they need.您将需要修改文件系统上的 ACL 以授予身份所需的访问权限。

try to set the domain user to the application pool identity.尝试将域用户设置为应用程序池标识。

usehttps://docs.microsoft.com/en-us/sysinternals/downloads/procmon to check where access is being blocked.使用https://docs.microsoft.com/en-us/sysinternals/downloads/procmon检查访问被阻止的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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