问题
I want to run a command line in ASP.NET 4.0 using C#. Actually I need to create a Web Service for doing this. How can I do that? I've read somewhere that when we run command line from Web, there can be some permission issues. If so, how can I overcome that?
回答1:
using(var cmd= new Process())
{
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = "";
cmd.Start();
}
The process is started with the same credentials the web service process is running with. The default is LocalSystem or NetworkService. Those might not have the proper permissions to do whatever you plan to do.
Keep in mind that doing things like this is considered unsecure and bad practice.
回答2:
Here you can take a look an example of class ProcessRunner that I created exactly for this purpose:
https://github.com/alexanderbeletsky/candidate.net/blob/master/Candidate.Core/System/ProcessRunner.cs
来源:https://stackoverflow.com/questions/6693829/how-do-i-run-a-command-line-process-from-a-web-application