简体   繁体   English

从ASPX页面权限问题运行PowerShell脚本

[英]Running powershell script from aspx page permission issues

I'm trying to run a powershell script from aspx page. 我正在尝试从aspx页面运行Powershell脚本。 I looked and googled around and found this piece of code from here named private string RunScript(string scriptText) (c# version) . 我环顾四周, 从这里发现了这段名为private string RunScript(string scriptText) (c# version) The problem is that I'm getting permission issues when I run the script using Visual Studio 2010. I tried running VS as an administrator but I got the same problem. 问题是使用Visual Studio 2010运行脚本时遇到权限问题。我尝试以管理员身份运行VS,但遇到了同样的问题。

What the aspx page does is it actually writes a powershell script and passes the string to scriptText . aspx页的作用是实际上编写了一个powershell脚本并将字符串传递给scriptText I confirmed that if I put the powershell lines in a file and run it on the command line it works. 我确认,如果我将Powershell行放入文件中并在命令行上运行它,则它可以工作。

Here's a sample of my powershell script that the aspx generates and tries to execute when a page is requested (using openxml powertools to merge pptx documents). 这是我的powershell脚本示例,当请求页面时,aspx会生成该示例并尝试执行该脚本(使用openxml powertools合并pptx文档)。

Import-Module Oxpt
$pml0 = New-PmlDocument "c:\MergeTemp\0.pptx"
$pres0 = New-Object OpenXmlPowerTools.SlideSource($pml0, $false )
$pml1 = New-PmlDocument "c:\MergeTemp\1.pptx"
$pres1 = New-Object OpenXmlPowerTools.SlideSource($pml1, $false )

$sources = ($pres0, $pres1)
Merge-Pptx -OutputPath c:\SlideMergeTemp\out.pptx -Sources $sources

If I place Set-ExecutionPolicy I get access to registry is denied . 如果我放置Set-ExecutionPolicy ,则无法access to registry is denied If I scope it to CurrentUser or LocalMachine I get error saying AuthorizationManager Check Failed . 如果我将其scope LocalMachineCurrentUserLocalMachine收到错误消息,提示AuthorizationManager Check Failed

How can I make this work? 我该如何进行这项工作? At some point I have to release this into production. 在某些时候,我必须将其发布。 What would be the correct permission to run the powershell script through the code using aspx page? 使用aspx页面通过代码运行powershell脚本的正确权限是什么?

I just used Process class executing powershell.exe and passing arguments to it. 我只是使用Process类执行powershell.exe并将参数传递给它。 It's not the best solution. 这不是最好的解决方案。 But then again, I don't see ya'll rushing to help and providing a solution either :-) 但是话又说回来,我也不希望你们急着提供解决方案:-)

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

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