简体   繁体   English

如何从Webform打开控制台应用程序

[英]How to open a console app from a webform

I have a collection of sites running on a single server. 我在单个服务器上运行着一些站点。 The server also runs a console application which collects data and distributes this data to the websites. 该服务器还运行一个控制台应用程序,该应用程序收集数据并将这些数据分发到网站。

I am not always about to check if the application is running and I would like to give the end user (a select few users!) the option to start/restart this application on the server by using a webform. 我并不总是要检查应用程序是否正在运行,我想为最终用户(选择几个用户!)提供使用Web表单在服务器上启动/重新启动此应用程序的选项。 (click a button and application starts). (单击按钮,应用程序启动)。

I have got the console application to start by using the following code: 我已经使用以下代码启动了控制台应用程序:

        ProcessStartInfo info = new ProcessStartInfo(FileName);
        Process App1 = null;
        App1 = Process.Start(info);

But no console window appears and I would like the console to open a window so that if I log onto the server I can check that the application is running. 但是没有控制台窗口出现 ,我希望控制台打开一个窗口,这样,如果我登录到服务器,就可以检查应用程序是否正在运行。

I have tried adding: 我尝试添加:

info.CreateNoWindow = false;

and a few other things, but this is not my area so I am struggling. 和其他一些事情,但这不是我的专长,所以我在努力。

Any ideas how I can get the console to open in a normal window? 有什么想法可以使控制台在正常窗口中打开吗? Or am I going about this all the wrong way? 还是我会以错误的方式进行处理?

Also, is there a way of finding if the application is running and either kill it before trying to start it, just restarting it, or not allowing the end user the option to do anything. 另外,还有一种方法可以找到应用程序是否正在运行,并在尝试启动它之前将其杀死,只是重新启动它,还是不允许最终用户选择执行任何操作。

Many thanks T 非常感谢T

ProcessStartInfo info = new ProcessStartInfo(FileName);
Process App1 = null;
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
App1 = Process.Start(info);

try using info.usershellexecute property 尝试使用info.usershellexecute属性

As Aristos says, the console app will open on the server...not the client. 正如Aristos所说,控制台应用程序将在服务器上打开,而不是在客户端上打开。

Look here for a start on how to open a process from asp and the security implications 在此处查找有关如何从asp打开进程的开始以及其安全隐患

If you need the client to be able to view anything I suggest having the service write to a log in a database and having the aspx page read this log. 如果您需要客户端能够查看任何内容,建议将服务写入数据库中的日志,并让aspx页读取此日志。

Also, maybe write your console app as a windows service, not just an application? 另外,也许将您的控制台应用程序编写为Windows服务,而不仅仅是一个应用程序?

Good example here 这里的好例子

Hope this helps. 希望这可以帮助。

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

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