IIS php powershell与用户开关

时间:2014-12-11 10:32:09

标签: php windows powershell iis

我有一个带有php 5.6的IIS。

我正在编写一个PHP脚本,它应该执行一个PowerShell脚本。

powershell脚本必须切换到另一个用户,因为IUSR用户没有powershell中所需命令的权限。

来源:

PowerShell的PHP调用:

$content = shell_exec("powershell.exe  -NonInteractive -command " . getcwd() . "\\ps-helper.ps1 -ps_password '".$powershell_password."' < NUL");

由于(据我所知)无法在脚本中切换用户,我将它们分成两个文件。 ps-helper.ps1应该使用不同的凭据启动第二个脚本:

PS-helper.ps1:

$psuser_secpassword  = ConvertTo-SecureString $ps_password -AsPlainText -Force
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.CreateNoWindow = $true
$psi.FileName = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$psi.Arguments = "/?"
$psi.UseShellExecute = $false;
$psi.RedirectStandardInput = $true;
$psi.RedirectStandardError = $true;
$psi.RedirectStandardOutput = $True;
$psi.Username = 'username'
$psi.Domain = 'DOMAIN'
$psi.Password = $psuser_secpassword
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $psi
$p.Start()
$stdout = $p.StandardOutput.ReadToEnd()
$stderr = $p.StandardError.ReadToEnd()
$p.WaitForExit()

如果我通过Windows中的cmd.exe以普通用户身份执行命令,则可以正常使用。

问题:

  • 如果我通过IIS执行命令它失败,没有给出任何理由(stdout和stderr为空)
  • 如果我注释掉用户名,域名和密码,它就有效 - 这意味着$ stdout填充了第二个脚本的输出(但显然没有用户更改)

Windows,IIS,PHP或PowerShell中是否存在阻止用户从IUSR更改为其他内容的设置?

0 个答案:

没有答案