且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何强制我的 .NET 应用程序以管理员身份运行?

更新时间:2023-10-22 23:00:10

您需要修改嵌入到程序中的清单.这适用于 Visual Studio 2008 及更高版本:项目 + 添加新项目,选择应用程序清单文件".将 元素更改为:

You'll want to modify the manifest that gets embedded in the program. This works on Visual Studio 2008 and higher: Project + Add New Item, select "Application Manifest File". Change the <requestedExecutionLevel> element to:

 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

用户在启动程序时会收到 UAC 提示.明智地使用;他们的耐心很快就会耗尽.

The user gets the UAC prompt when they start the program. Use wisely; their patience can wear out quickly.