为什么 Windows 上的应用程序在注销时会以系统帐户运行
我有一个 ac# 应用程序,它在计算机上的系统帐户下启动,并向用户显示一些对话框。 当普通用户注销时,应用程序也会终止。 我本以为,由于它在系统帐户下运行,尽管用户未登录,它仍会继续运行。
任何有关为什么会发生这种情况的信息将不胜感激。
I have a c# application which is launched under the System account on a machine and presents some dialogs to a user. When a regular user logs off the application is terminated as well. I would have thought that since its running under the system account it would continue to run despite the user not being logged in.
Any info on why this happens would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的应用程序是服务吗? 听起来您想要的是服务。 请注意,您可以以任何用户身份运行任何进程,但这并不意味着它成为服务。 如果您的进程作为服务实现,那么即使没有用户登录,它也会继续运行。
Is your application a service? It sounds like what you want is a service. Note that you can run any process as any user, but that doesn't make it a service. If your process is implemented as a service, then it will continue running even with no users logged in.
如果您希望您的应用程序在用户注销后继续运行(例如,只要计算机正在运行就保持状态),您需要一项服务。 但是,强烈建议不要让服务显示 UI。 如果您需要长时间运行和 UI,请考虑编写一个服务来存储数据,以及一个在每次用户登录时运行的应用程序,以显示 UI 并与服务交互。
If you want your app to keep running after the user has logged off (e.g. to maintain state for as long as the computer is running), you need a service. However, services are strongly discouraged from displaying UI. If you need both long-running and UI, consider writing a service to store your data, and an application that runs each time a user logs in that shows UI and interacts with the service.
这是一项安全功能,当用户会话结束时,他们调用的应用程序将被终止。 如果您需要一个应用程序在用户会话之外运行,那么您需要一个服务,但是因为它在自己的会话服务中无法通过消息等“到达”用户会话。
This is a security feature when a users session ends applications they invoked are terminated. If you need an application to run outside of a users session you need a service however since its in its own session services cant "reach into" the users session with messages and such.
您需要将应用程序作为 Windows 服务运行。
You need to run your application as a Windows Service.
您需要将应用程序创建为 Windows 服务。 如果您的应用程序显示对话框,那么您需要选中“允许服务与桌面交互”并在本地系统帐户下运行它。
但是,更好的方法是使用 WCF 或远程处理从应用程序公开可查询接口,您可以使用单独的应用程序向用户显示该接口。 如果您希望在无人登录时从应用程序收到通知,那么您可能需要考虑发送电子邮件或将事件发布到单独的 WCF/Web 服务/远程处理端点。
You will need to create your application as a windows service. If your application displays dialogs then you would need to check the 'Allow service to interact with desktop' and run it under local system account.
However, a better approach would be to expose a queryable interface from your application using WCF or Remoting that you can display to users using a separate application. If you want notifications from your app when no one is logged on then you might want to consider sending emails or posting events to a separate WCF/ Web Services/ Remoting endpoint.
由于该进程是由 explorer.exe 启动的,因此当用户注销时,无论它在哪个帐户下运行,该进程都会终止。 这就是 Windows 的工作方式。 为了允许进程继续运行,它需要是一个服务或者可能由任务调度程序启动。
Because the process was started by explorer.exe, it will be terminated when the user logs off regardless of what account it's running under. That's simply the way windows works. To allow the process to continue running it needs to be a service or possibly started by the task scheduler.