windows 如何以管理员身份运行部署应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2432329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I deploy applications in run as administrator mode?
提问by Ivan Prodanov
How Do I deploy applications so that they require administrator rights without the end-user doing that by hand?
我如何部署应用程序以便它们需要管理员权限而无需最终用户手动执行?
I use Delphi 2009 to build the application.
我使用 Delphi 2009 来构建应用程序。
回答by Bradley Grainger
You can inform Windows that your application needs to run as an administrator by using the requestedExecutionLevel
element in your application manifest.
您可以使用requestedExecutionLevel
应用程序清单中的元素通知 Windows 您的应用程序需要以管理员身份运行。
The manifest file is an XML file that looks as follows. It should be named YourApp.exe.manifestand placed in the same folder as the executable. (It can also be embedded in the resources of your application; it must have a resource type of RT_MANIFEST
and an ID of 1.)
清单文件是一个 XML 文件,如下所示。它应该命名为YourApp.exe.manifest并放置在与可执行文件相同的文件夹中。(它也可以嵌入到您的应用程序的资源中;它的资源类型必须RT_MANIFEST
为 1,ID 必须为 1。)
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="YourApp" type="win32"/>
<description>Description of your application</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
For further details on application manifests and how to create them, see Create and Embed an Application Manifest (UAC)at MSDN.
有关应用程序清单以及如何创建它们的更多详细信息,请参阅MSDN 上的创建和嵌入应用程序清单 (UAC)。
Note that the manifest is only respected by Windows Vista and later. If your user is running as a standard user on Windows XP, your application will not be launched as an administrator; you may need to write code to detect this if it will be a problem for your application.
请注意,清单仅适用于 Windows Vista 及更高版本。如果您的用户在 Windows XP 上以标准用户身份运行,您的应用程序将不会以管理员身份启动;如果这对您的应用程序造成问题,您可能需要编写代码来检测它。
回答by skamradt
Another option, although not recommended for "every day applications", is to name your executable with "Install" or "Setup" as part of the name. Keep in mind that if you don't change any registry settings, or create any new files then windows will display a warning to the user that the program might not have run properly.
另一种选择,虽然不推荐用于“日常应用程序”,但将您的可执行文件命名为“安装”或“设置”作为名称的一部分。请记住,如果您不更改任何注册表设置或创建任何新文件,则 Windows 将向用户显示程序可能无法正常运行的警告。