简体   繁体   English

在我登录 Windows 之前,如何启动 WPF 应用程序?

[英]How can a WPF application be launched before I logon to Windows?

I would like to run WPF application before logging in to Windows.我想在登录 Windows 之前运行 WPF 应用程序。 It shouldn't do any of existing UI just call ApplicationStartup event - it would trigger the functions I need.它不应该做任何现有的 UI 只是调用 ApplicationStartup 事件 - 它会触发我需要的功能。

Currently I'm using a windows service in conjunction with app, so service runs before logging in.目前我正在将 windows 服务与应用程序结合使用,因此服务在登录之前运行。

The downside now is that my app doesn't know what the service is doing without polling it.现在的缺点是我的应用程序不知道服务在做什么而不轮询它。

And this is a requirement as machines can crash and restart itself, but Windows should still be running application anyway after boot up.这是一个要求,因为机器可能会崩溃并自行重新启动,但 Windows 在启动后应该仍然在运行应用程序。

Is there any way?有什么办法吗?

No, this is not possible.不,这是不可能的。 WPF applications are user-mode applications, so they must be run within the context of a logged-in user. WPF 应用程序是用户模式应用程序,因此它们必须在登录用户的上下文中运行。 Since Windows is a multi-user operating system, it is possible for the OS to be running, but no users to be logged in. In those situations, there is no place for your application to run.由于 Windows 是一个多用户操作系统,因此操作系统可能正在运行,但没有用户登录。在这种情况下,您的应用程序将无处可运行。

Windows services are the only thing that can do this, and that's precisely because they do not run under a particular user context. Windows 服务是唯一可以做到这一点的东西,这正是因为它们不在特定的用户上下文下运行。 In fact, this same feature is often a source of frustration for developers who want to create a Windows service that interacts with the user.事实上,对于想要创建与用户交互的 Windows 服务的开发人员来说,同样的功能常常是一个令人沮丧的原因。 That's not possible (at least not as of Windows Vista, which patched all the security holes present in prior versions). 这是不可能的(至少从 Windows Vista 开始,它修补了之前版本中存在的所有安全漏洞)。

Alternative solutions:替代解决方案:

  • Add your application to the default user's "Startup" folder, which will force it to launch each time that a user logs in to the machine.将您的应用程序添加到默认用户的“启动”文件夹,这将强制它在每次用户登录机器时启动。

    In this scenario, the only time it will not be running is when no users are logged in, in which case it's sort of hard to imagine that your app/service is actually doing anyone any good.在这种情况下,它不会运行的唯一时间是没有用户登录,在这种情况下,很难想象您的应用程序/服务实际上对任何人都有好处。

  • Configure each machine to automatically log in as a particular user whenever Windows starts up.将每台机器配置为在 Windows 启动时自动以特定用户身份登录。 Combining this with the above, you work around the fact that the computer could ever be left without a user logged in, even immediately after a crash/restart.将其与上述内容结合起来,您可以解决这样一个事实,即即使在崩溃/重新启动之后,计算机也可能在没有用户登录的情况下离开。

Although the pattern of having a separate user-mode application (WPF, WinForms, or whatever) that can show a UI control the Windows service running in the background is quite a common one.尽管拥有可以显示 UI 控件的单独用户模式应用程序(WPF、WinForms 或其他)的模式在后台运行 Windows 服务是很常见的一种。 I'm not sure what you think is wrong with that setup.我不确定您认为该设置有什么问题。 There's nothing wrong with polling the service when necessary for information.在必要时轮询服务以获取信息并没有错。 Services by definition do not require user intervention.根据定义,服务不需要用户干预。 Separating the part that requires user intervention out into a separate app is not only the typical practice, but necessary.将需要用户干预的部分分离到一个单独的应用程序中不仅是典型的做法,而且是必要的。

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

相关问题 如何为我制作服务登录Windows? - How can I make a service logon Windows for me? WPF ContextMenu:我怎么知道是谁启动的? - WPF ContextMenu: How can I tell who launched it? 如何在 windows 启动时延迟 WPF 应用程序的启动? - How can I delay the start of WPF application on windows startup? 我可以使用logonuser(…)函数登录Windows 7吗? - Can I use logonuser(…) function to logon to windows 7? 如何获取列表本地Windows用户(仅Windows登录屏幕中显示的用户) - How can I get a list Local Windows Users (Only the Users that appear in the windows Logon Screen) Windows登录前运行.exe - Run .exe before windows logon WPF:如何在我的应用程序窗口之前显示我的登录窗口(项目导入)? - WPF : How can i show my login window(project imported) before my application window? 如何获取Active Directory用户列表(仅Windows登录屏幕中显示的用户) - How can I get a list of Active Directory Users (Only the Users that appear in the windows Logon Screen) 如何构建可以在窗口之间拖放用户控件的 WPF 应用程序? - How do I build a WPF application where I can drag and drop a user control between windows? 如何将控制台输出添加到Windows wpf应用程序C# - How can i add a console output to a windows wpf application C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM