I'm trying to run a powershell script from aspx page. I looked and googled around and found this piece of code from here named 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.
What the aspx page does is it actually writes a powershell script and passes the string to scriptText
. I confirmed that if I put the powershell lines in a file and run it on the command line it works.
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).
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
. If I scope
it to CurrentUser
or LocalMachine
I get error saying 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?
I just used Process class executing powershell.exe and passing arguments to it. It's not the best solution. But then again, I don't see ya'll rushing to help and providing a solution either :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.