duanjing7298 2014-12-11 10:32
浏览 36

IIS php powershell与用户开关

I have an IIS with php 5.6.

I am writing a PHP script, which should execute a powershell script.

The powershell script has to switch to another user because the IUSR user does not have the privileges for the needed commands in the powershell.

Source:

PHP call of powershell:

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

As it is (to my knowledge) not possible to switch user within a script, I split them up in two files. the ps-helper.ps1 should start the second script with different credentials:

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()

If I execute the command via cmd.exe in windows as normal user, it works fine.

Problem:

  • If I execute the command via IIS it fails, no reason given (stdout and stderr are empty)
  • If I comment out Username, Domain and Password, it works - meaning $stdout is filled with output from second script (but obviously no user change)

Are there any settings in Windows, IIS, PHP or powershell that prevent user change from IUSR to something else?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c