如何在 Visual Studio 2005 中使用 Manifest 文件以管理员权限运行应用程序?
我需要创建一个应用程序,该应用程序需要在 "C:Program Files","Users[username]" 和 Sys32 中创建文件/文件夹.应用程序还需要创建一些注册表项.
I need to create an application which needs to create files/folders in "C:Program Files","Users[username]" and Sys32. Also the application needs to make some registry entry.
此应用程序需要在 Vista 及更高版本上运行.此外,在 Windows Server 2003 及更高版本上.
This application needs to work on Vista and higher. Also, on Windows Server 2003 and higher.
上述操作系统有用户账户控制(UAC)的概念,在哪里访问程序文件和写入注册表需要管理员权限.
The above Operating Systems have the concept of User Account Control (UAC), where to access Program Files and writing in registry requires admin privileges.
我查看了很多论坛,发现使用Microsoft SDK我们可以检查当前用户是否具有管理员权限.但是对于 Vista 及更高版本的操作系统,CheckTokenMembership"功能失败.
I looked into many forums and found that using Microsoft SDK we can check whether the current user have admin privileges or not . But the function "CheckTokenMembership" fails for Vista and higher version of OS.
我还找到了一个解决方案,可以使用清单文件提前告诉操作系统当前应用程序需要管理员权限.这是使用requestedExecutionLevel"标签完成的.
I also found a solution where manifest file can be used to tell OS in advance that the current application requires admin privileges. This is done using "requestedExecutionLevel" tag.
我正在使用 Visual Studio 2005 创建应用程序.当我们在 Visual Studio 中创建应用程序时,会创建一个默认清单文件.我可以更改此清单文件以包含requestedExecutionLevel"标签,以便我的应用程序始终以管理员权限运行吗?
I am using Visual Studio 2005 to create the application. When we create an application in Visual Studio a default manifest file is created. Can I change this manifest file to include "requestedExecutionLevel" tag, so that my application always runs with admin privileges?
是否有任何其他方法可以让我的应用程序以管理员权限运行而不要求用户(管理员或标准)以以管理员身份运行"运行我的应用程序??
Is there any other method through which my application runs with admin privileges without asking user (admin or standard) to run my application as "run as admin"??
谢谢!
推荐答案
你应该在项目属性 Linker -> Manifest File -> UAC Execution Level 中找到一个选项.将此设置为 requireAdminstrator
.
You should find an option for this in project properties Linker -> Manifest File -> UAC Execution Level. Set this to requireAdminstrator
.
这将导致默认生成的清单包含您需要的 requestedExecutionlevel
,因此如果您的用户尚未提升权限,则会自动提示他们提升他们的权限.
This will cause the default generated manifest to include the requestedExecutionlevel
that you need, so that your users will be prompted automatically to elevate their privileges if they are not already elevated.
相关文章