Windows 7 UAC 提升

发布于 2024-08-29 19:47:10 字数 324 浏览 5 评论 0原文

我有一个线程,我想在我的应用程序中以管理员身份运行。应用程序的其余部分我可以愉快地以默认用户级别 (asInvoker) 运行。这可能吗?我注意到有一个“ImpersonateLoggedOnUser”功能。我可以以某种方式使用它来登录管理员,然后让线程模拟该人吗?

看起来这应该是一件相当微不足道的事情……但似乎没有任何明显的方法可以做到这一点。有人可以帮我吗?

编辑:因此,如果我必须启动一个单独的进程,有什么方法可以 CreateProcess 一个新进程并让它从特定的入口点启动。当然,我可以使用命令行处理来完成此操作,但我真的希望能够阻止用户输入命令行并启动不可关闭的进程!

I have a single thread that I'd like to run as an administrator in my application. The rest of the application I can happily run as the default user level (asInvoker). Is this possible? I notice there is an "ImpersonateLoggedOnUser" function. Can I somehow use this to log the administrator on and then get the thread to impersonate that person?

It seems as though this ought to be something pretty trivial to do ... but there doesn't appear to be any obvious way to do it. Can anyone help me out?

Edit: So if I have to fire off a seperate process is there any way I can CreateProcess a new process and have it launch from a specific entry point. I can, of course use command line processing to do it, but i'd really rather I could stop the user from entering the command line and starting an unclosable process!

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

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

发布评论

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

评论(3

若相惜即相离 2024-09-05 19:47:10

不,提升是每个进程,而不是线程。

如果应用程序的其余部分必须以非提升的方式运行,您可以使用某些参数(myapp.exe /uac“ipcparamhere”)运行自己的提升版本,并使用某种进程间通信用于与应用程序的“主实例”进行通信。 (如果提升的进程只执行简单的操作,您可以使用进程的退出代码检查是否成功)

No, elevation is per process, not thread.

If the rest of the application has to run non-elevated, you could run yourself elevated with some parameter (myapp.exe /uac "ipcparamhere") and use some sort of Inter-process communication to communicate back to the "main instance" of your app. (If the elevated process only performs a simple operation, you could probably check for success by using the exit code of the process)

浅唱ヾ落雨殇 2024-09-05 19:47:10

这是不可能的。您需要通过在应用程序中包含清单来获得管理员权限。谷歌“requireAdministrator”找到您需要的清单。您的用户可能很快就会厌倦一遍又一遍地执行此操作,最好的选择是将需要这些权限的任务分拆到一个单独的进程中。以服务为例。

This is not possible. You'll need to gain admin privileges by including a manifest in the app. Google "requireAdministrator" to find the manifest you'll need. Your user will probably quickly tire of doing this over and over again, your best bet is to spin-off the task that requires these privileges into a separate process. A service for example.

人生戏 2024-09-05 19:47:10

您可以启动一个单独的 exe,并在其上有一个清单,说明它需要管理员。然后一定要使用 shell 执行来启动它,它使用清单,然后一切就都准备好了。作为一个深思熟虑的做法,在启动该线程的按钮上放置一个 UAC 防护罩。 (如果您手动执行这一切,请向其发送 BCM_SETSHIELD 消息。)

您可以在单独的进程上决定是否需要可见窗口。同时,用户仍然可以拖放到主应用程序中。

You can launch a separate exe and have a manifest on it saying it requires administrator. Then be sure to launch it with shell execute, which uses manifests, and you're all set. As a thoughtful touch, put a UAC shield on the button that kicks off that thread. (Send it a BCM_SETSHIELD message if you're doing this all by hand.)

You can decided whether you want a visible window or not on the separate process. Meanwhile the user can still drag and drop into the main app.

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