Vista 下安装服务并添加注册表项

发布于 2024-10-03 23:49:53 字数 666 浏览 0 评论 0原文

我有一个程序作为桌面应用程序运行,但也可以作为 Windows 服务安装。安装是通过使用 GUI 上的“安装为服务”按钮来完成的。该按钮的事件处理程序如下所示:

ProcessStartInfo psi = new ProcessStartInfo("sc", "description " + 
   this.ServiceName + "  \"" + 
      ((AssemblyDescriptionAttribute)attributes[0]).Description + "\"") 
psi.CreateNoWindow = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.Verb = "runas";
Process.Start(psi).WaitForExit();    

我现在想做的是在 say: 下添加一些额外的注册表项,

HKLM\SOFTWARE\MyCompany\Services

这也需要提升的权限。但是,如果我使用与上述相同的过程和命令“REG ADD”,UAC 对话框将出现多次 - 我不希望出现这种情况。

那么,安装 Windows 服务并在 HKLM 下添加注册表项且仅出现一次 UAC 提示的最佳方法是什么?

I have a program that runs as a desktop application, but can also be installed as a windows service. The installation is done by using an "install as service" button on the GUI. The event handler for this button looks like this:

ProcessStartInfo psi = new ProcessStartInfo("sc", "description " + 
   this.ServiceName + "  \"" + 
      ((AssemblyDescriptionAttribute)attributes[0]).Description + "\"") 
psi.CreateNoWindow = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psi.Verb = "runas";
Process.Start(psi).WaitForExit();    

What I would like to do now is to add some additional registry entries under say:

HKLM\SOFTWARE\MyCompany\Services

which also needs elevated privileges. But if I use the same procedure as described above with the command "REG ADD" the UAC dialog would appear more than once - and I don't want that.

So whats the best way to install a windows service and add a registry entry under HKLM with only having the UAC prompt once?

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

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

发布评论

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

评论(3

岁月打碎记忆 2024-10-10 23:49:53

创建一个小型 exe 或批处理文件来执行这两项操作(sc 和 reg 更新)。启动that而不是sc。

Create a small exe or a batch file that does both things (the sc and the reg update). Launch that instead of sc.

被你宠の有点坏 2024-10-10 23:49:53

至于安装服务。
您可以尝试 topshelf。它易于使用且功能非常强大。

As for installing service.
You can try topshelf. It is easy to use and very powerful.

a√萤火虫的光℡ 2024-10-10 23:49:53

我最终使用管理员权限和特殊参数 myprogram.exe -i 调用自己,然后分支到一个特殊方法,该方法使用 ServiceInstaller 类将程序安装为服务(而不是调用 sc)。

I ended up calling myself with admin priviliges and a special parameter myprogram.exe -i and then branch into a special method which uses the ServiceInstaller class to install the program as a service (instead of calling sc).

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