如何设计在 Windows Vista/7 上以管理员身份运行的自动启动应用程序?
我的应用程序需要根据某些事件启动和停止 Windows 服务。问题是这个应用程序需要以提升的普通用户身份运行(为了停止服务),并且在 Windows 启动时自动启动。此外,它需要位于带有用户界面的系统托盘中。
我在这里有什么选择?
我认为至少有两种可能性:
- 通过将应用程序放入启动文件夹或注册表中的 ..\Run 键来使应用程序自动启动。但问题是,这样是否可以做到Windows每次启动时都不会弹出UAC提示对话框呢?
- 开发一个 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:
- 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?
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一定要使用选项 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.
实际上,使用第 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
对于第一点,为了以管理员权限运行您的应用程序,那么在不弹出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.
您可以使用计划任务工具来完成您想要的任务。对于调度,有一个选项可以安排程序在用户登录时运行。有一些选项可以使用备用凭据运行任务。
我无法告诉您如何以编程方式进行设置(可能有一个 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.