简体   繁体   English

如何通过ASP.Net(C#或VB)运行服务器端应用程序

[英]How to run a server-side application via ASP.Net(C# or VB)

I wanted to build a front end web page so that I can start and stop various programs on my server remotely. 我想建立一个前端网页,以便可以远程启动和停止服务器上的各种程序。 I know that Shell will open something locally, but how can I make an ASP.Net page which activates programs server-side? 我知道Shell将在本地打开某些内容,但是如何制作一个ASP.Net页面来在服务器端激活程序? Googling got me the "Shell" method, but I don't think that works server-side. 谷歌搜索使我有了“ Shell”方法,但我认为这在服务器端不起作用。 Any ideas? 有任何想法吗?

Take a look at the System.Diagnostics.Process class. 看一下System.Diagnostics.Process类。 It can allow you to start and stop an executable on the server. 它可以允许您启动和停止服务器上的可执行文件。

You would have to impersonate an account that has sufficient privileged to run the application, though. 但是,您将必须模拟一个具有足够特权来运行该应用程序的帐户。 You can use the UserName and Password properties of the System.Diagnostics.ProcessStartInfo object that you pass to Process.Start . 您可以使用传递给Process.StartSystem.Diagnostics.ProcessStartInfo对象的UserNamePassword属性。

Edit 编辑

For an example, you could do the following: 例如,您可以执行以下操作:

var startInfo = new ProcessStartInfo("C:\MyServerApp.exe", "/A /B /C");
startInfo.UserName = "LocalUser";
// It's a bad idea to hard code the password in the app, this is just an example
startInfo.Password = "SomePass";

var process = Process.Start(startInfo);

// Not a good idea to wait in a web app, but you can until the process completes
process.WaitForExit();

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

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