samedi 30 août 2014

executing windows powershell not working fo riis 7.5 (windows 2008 r2) web application


Vote count:

0




I made ASP.NET MVC4 Web application program that execute doc file by using power shell script


In my PC, It works very well.(Windows 7, visual studio express 2013 for web)


But when I deployed this application in real server, server didn't execute doc file. (server environment : windows server 2008 r2, iis 7.5)


I confirmed that real server has "test.doc" file in c drive.


Also, it didn't give any error message to me.


How can I do?



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Test.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/

public ActionResult Index()
{
return View();
}

public string Test()
{
string filepath = "c:\\test.doc";
string script = "start-process -filepath \"" + filepath + "\"";

// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();

// open it
runspace.Open();

// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);

// add an extra command to transform the script
// output objects into nicely formatted strings

// remove this line to get the actual objects
// that the script returns. For example, the script

// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.

pipeline.Commands.Add("Out-String");

// execute the script
Collection<PSObject> results = pipeline.Invoke();

// close the runspace
runspace.Close();

// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return "test";
}

}
}


asked 1 min ago







executing windows powershell not working fo riis 7.5 (windows 2008 r2) web application

Aucun commentaire:

Enregistrer un commentaire