仅在需要时进行特权提升

发布于 2024-09-06 05:41:37 字数 394 浏览 1 评论 0原文

我的应用程序只是偶尔需要权限提升...我需要引用一些第 3 方 COM 组件,这些组件仅在以管理员身份运行时才能正常工作。

我希望我的应用程序仅在需要时请求权限提升...通常,我不希望我的应用程序以管理员身份运行,除非我需要使用第 3 方 COM 组件。

我发现 CoCreateAsAdmin 可以潜在解决问题,但组件作者没有设置所需的注册表项,并且我不确定如何在 C# 中使用 CoCreateAsAdmin 并与 Runtime-Callable 结合使用-由 tlbimp 创建的包装器。

另一个解决方案是生成另一个进程,但我还没有这方面的经验...我不想创建一个完全独立的应用程序...我很乐意创建一个在单独的提升进程中运行的程序集,如果有人可以告诉我如何让它发挥作用。

谢谢...

My application only very occasionally requires privilege elevation... I need to reference some 3rd party COM components that only work correctly when run as administrator.

I would like my application to request privilege elevation only when it needs it... Generally, I don't want my application to run as administrator unless I need to use the 3rd party COM components.

I see that CoCreateAsAdmin could potentially solve the problem, but the component author doesn't set up the required registry entries, and I'm not sure how to use CoCreateAsAdmin in C# and in conjuction with Runtime-Callable-Wrapper that is created by tlbimp.

Another solution would be to spawn another process, but I have no experience with this yet... I don't want to create a completely separate application... I would be happy to create an assembly that runs in a separated elevated process if someone can show me how to make it work.

Thanks...

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

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

发布评论

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

评论(1

○愚か者の日 2024-09-13 05:41:38

进程权限基于进程运行时使用的用户令牌,该令牌仅在进程启动时分配。因此,在流程启动后,没有任何方法可以提升流程。在运行时提升的唯一可靠方法是生成一个新进程。

幸运的是,这非常简单。使用 Process 对象执行将注册并启动 COM 服务器的命令行。确保您正在运行的 .exe 的应用清单将其标记为需要提升,并且在运行之前会自动提示用户。

Process privileges are based on the user token that the process is running under, which is only assigned when the process starts. Therefore there isn't any way to elevate your process after it's already started. The only reliable way to elevate at runtime is to spawn a new process.

Fortunately, this is pretty easy. Use the Process object to execute the command-line that will register and launch the COM server. Make sure that the app manifest of the .exe you're running marks it as requiring elevation, and the user will automatically be prompted before it runs.

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