如何设计在 Windows Vista/7 上以管理员身份运行的自动启动应用程序?

发布于 2024-08-22 19:09:15 字数 372 浏览 6 评论 0原文

我的应用程序需要根据某些事件启动和停止 Windows 服务。问题是这个应用程序需要以提升的普通用户身份运行(为了停止服务),并且在 Windows 启动时自动启动。此外,它需要位于带有用户界面的系统托盘中。

我在这里有什么选择?
我认为至少有两种可能性:

  1. 通过将应用程序放入启动文件夹或注册表中的 ..\Run 键来使应用程序自动启动。但问题是,这样是否可以做到Windows每次启动时都不会弹出UAC提示对话框呢?
  2. 开发一个 Windows 服务,安装后作为系统运行,并在系统托盘中提供单独的 GUI 应用程序。但是,为了在提升的服务和正常的系统托盘应用程序之间进行通信,我在这里有哪些 IPC 可能性?

有什么想法和建议吗?

I have the need for my application to start and stop Windows Services based on certain events. The thing is that this application needs to run as an elevated normal user (In order to stop services), as well as auto start when Windows starts. Additionally, it need to be in the systray with an user interface.

What are my options here?
I suppose that there are at least two possibillities:

  1. To make the application auto start by putting it in the Startup folder or in the ..\Run key in the registry. But the question is, can this be done without the UAC prompt dialog pops up every time Windows starts?
  2. Develop a Windows Service that is installed to run as system, with a separate GUI app in the sys tray. But what are the IPC prossibilities I have here in order to communicate between the elevated service and the normal sys tray app?

Any thoughts and recommendations?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

命硬 2024-08-29 19:09:16

一定要使用选项 2,特别是使用 WCF (Windows Communication Foundation) 通过 wsHTTPS 绑定与 Windows 服务进行通信,以便您可以验证登录的用户是否有权在 Windows 服务托管的 WCF 服务上执行操作。

Definitely go with option 2 and specifically use WCF (Windows Communication Foundation) to communicate with the Windows Service using wsHTTPS binding so that you can authenticate that the logged in user is allowed to perform the actions on the WCF Service hosted by the Windows Service.

迷雾森÷林ヴ 2024-08-29 19:09:16

实际上,使用第 1 种方法,您可以将几个进程链接在一起,以实现无需 UAC 对话框的提升进程。像这样

第一个过程->以管理员身份启动(需要一种提供凭据的方法)->使用 ShellExecute 启动另一个进程并提供 Runas动词。 ->您的最终流程

Actually with number 1 you can chain a couple processes together to achieve an elevated process without a UAC dialog. Like this

First Process-> Launch as Administrator (will need a way to supply credentials) -> launch another process using ShellExecute and supplying the Runas verb. -> Your final process

等待圉鍢 2024-08-29 19:09:16

对于第一点,为了以管理员权限运行您的应用程序,那么在不弹出UAC对话框的情况下就不可能运行它,或者您拥有管理员密码

对于第二点,这是一个有趣的话题,这里有一篇很好的文章,带有示例&源代码: http://www.codeproject.com/KB/threads/process_communication.aspx 主题是.net 远程处理。我确信这是不同应用程序之间通信的最佳方式。

For number 1, in order to run your application with administrator permissions, then it is impossible to run it without the UAC dialog poping up, or you having the administrator password

For number 2, this is an interesting topic, there is a good article here, with examples & source codes: http://www.codeproject.com/KB/threads/process_communication.aspx the topic is .net remoting. im sure that is the best way to communicate between the different apps.

厌味 2024-08-29 19:09:16

您可以使用计划任务工具来完成您想要的任务。对于调度,有一个选项可以安排程序在用户登录时运行。有一些选项可以使用备用凭据运行任务。

我无法告诉您如何以编程方式进行设置(可能有一个 WMI 界面),但通过 UI 可以轻松完成。

You can use the Scheduled Tasks facility to accomplish what you want. For scheduling there is an option to schedule a program to run whenever a user logs on. There are options for running the task with alternate credentials.

I couldn't tell you how to set this up programatically (there's probably a WMI interface for it) but it's easy to do through the UI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文