从 Windows 服务启动 WinForms 应用程序 [英] Start WinForms application from Windows Service

查看:35
本文介绍了从 Windows 服务启动 WinForms 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个(第 3 方)WinForms 应用程序,我需要在 Windows Server 上全天候 24/7 保持活动状态.我的第一个想法是编写一个 Windows 服务来启动应用程序(使用 System.Diagnostics.Process)并在它崩溃或服务器重新启动时重新启动它.

I have a (3rd party) WinForms application that I need to keep alive 24/7 on a Windows Server. My first thought was to write a Windows Service that starts the application (using System.Diagnostics.Process) and restarts it if it should crash or the server is restarted.

这甚至可能吗?即使没有用户在服务器上登录,我也需要它启动.当没有人登录时,具有用户界面的应用程序能否运行?如果没有,是否有解决方法?

Is this even possible? I need it to start even if no user is signed in on the server. Can an application with a user interface run when no one is logged in? If no, is there a workaround?

注意我不需要以任何方式与应用程序交互,我只需要启动它.

N.B. I don't need to interact with the application in any way, I just need to start it.

推荐答案

我建议您考虑不同的方法.尝试通过 Windows 服务向用户显示 GUI 并不是一件容易的事,我遇到了类似的情况,最后我不得不采用不同的方法.

I would suggest you to think of a different approach. trying to show a GUI to user through windows service is not going to be a easy task, I came accross similar situation and finally i had to go for a different approach.

为什么不能直接从 Service 中显示 UI:这是由于一些安全实现使用 Windows Vista 和更高版本的操作系统进入 Windows 操作系统.Microsoft 禁止 Windows 服务直接与用户桌面,因为它导致了一些安全漏洞

Why can't you directly show UI from Service : This is due to some security implementation went into windows OS with Windows Vista and later OS versions. Microsoft disallowed windows services from directly interacting with user desktop as it led to some security flaw

-

我不需要以任何方式与应用程序交互

I don't need to interact with the application in any way

如果是这样,我假设应用程序不需要任何用户交互来继续其操作,它会自己做吗?如果那么你甚至可以去命令提示符 exe.

if thats the case, I assume that application doesnt need any user interaction to continue its operation it will do its own ? if then you can even go for a command prompt exe.

即使没有用户在服务器上登录,我也需要它启动

I need it to start even if no user is signed in on the server

我强烈建议您使用 Windows 任务调度程序.这将使您的生活更加轻松.它不需要任何用户手动启动程序,它可以在计算机启动/重新启动时启动您的程序,甚至您可以安排在特定时间间隔运行您的程序.您还可以查看其他优秀的 .net 任务调度库,quartznet 就是其中之一.

I would strongly recommend you to go for Windows Task Scheduler. Which will make your life much more easier. it doesnt require any user to manually start the program, It can start your progarm when computer starts/re-starts or even you can schedule to run your program on specific intervals. You can also check other good .net task scheduling libraries, quartznet is one of them.

这篇关于从 Windows 服务启动 WinForms 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆