是否有 API 调用来提示用户进行 UAC 提升? [英] Is there an API call to prompt user for UAC elevation?

查看:27
本文介绍了是否有 API 调用来提示用户进行 UAC 提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要写入 \ProgramData 中可以受到保护的文件.这只会在安装后发生一次.

My app needs to write to a file in \ProgramData that could be protected. This only happens once after installation.

是否有 API 函数可以获取 ACL 信息并提示用户授权应用访问文件?换句话说,该应用程序会要求 Windows 提示用户进行确认和授权.这应该以交互方式发生,并允许应用在获得文件访问权限后恢复执行.该应用程序以标准用户身份运行,不需要管理员权限.

Is there an API function that would take ACL info and prompt the user to authorize the app to access the file? In other words the app would ask Windows to prompt the user for confirmation and authorization. This should happen interactively, and allow the app to resume execution after access to the file has been authorized. The app runs as Standard User, does not require Admin privilege.

文件使用 CreateFile() 打开.

The file gets opened with CreateFile().

我的查询和其他被称为重复的查询之间存在细微差别.我正在请求访问一个特定对象(文件)的权限.其他人则要求提升整个过程的权限.无论如何,我感谢所有包含解决方案的回复.

推荐答案

如果您不想提升整个应用,您有几个选择:

If you don't want to elevate your entire app, you have a few options:

  1. 产生一个单独的提升进程只是为了访问文件.将 ShellExecute/Ex()runas 动词一起使用,或 CreateProcessElevated(),运行您的应用程序的第二个副本,或另一个助手应用程序,使用命令行参数告诉它要做什么.如果需要,主进程可以等待第二个进程退出.

  1. spawn a separate elevated process just to access the file. Use ShellExecute/Ex() with the runas verb, or CreateProcessElevated(), to run a second copy of your app, or another helper app, with command-line parameters to tell it what to do. The main process can wait for the second process to exit, if needed.

创建一个 COM 对象来访问该文件,然后使用 COM Elevation Moniker 以提升状态运行 COM 对象.

create a COM object to access the file, and then use the COM Elevation Moniker to run the COM object in an elevated state.

使用 <提示用户输入凭据code>CredUIPromptForCredentials()CredUIPromptForWindowsCredentials()(请参阅向用户询问凭据更多详细信息),然后使用 LogonUser() 要获取令牌,请使用 ImpersonateLoggedOnUser() 模拟该令牌,根据需要访问文件,然后停止使用 RevertToSelf() 并使用 CloseHandle().

prompt the user for credentials using CredUIPromptForCredentials() or CredUIPromptForWindowsCredentials() (see Asking the User for Credentials for more details), then logon to the specified account using LogonUser() to get a token, impersonate that token using ImpersonateLoggedOnUser(), access the file as needed, and then stop impersonating using RevertToSelf() and close the token with CloseHandle().

这篇关于是否有 API 调用来提示用户进行 UAC 提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆