How do I run a command line process from a web application?

好久不见. 提交于 2020-01-06 13:12:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!