如何删除 C# 中的“以管理员身份运行”要求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11457564/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:55:14  来源:igfitidea点击:

How to remove the "Run as Administrator" requirement in C#

c#admin

提问by Gary

I have a program that uses the registry to save the last 10 files that have been opened. At one time I was trying to save them in local machine, but instead decided to save them in the current user. During the course of trying to get everything to work I created a manifest to force the program to Run As Administrator, which I don't beleive is required any more. The problem I'm having is I can't seem to remove the requirement.

我有一个程序,它使用注册表来保存最近打开的 10 个文件。有一次我试图将它们保存在本地机器中,但决定将它们保存在当前用户中。在尝试让一切正常工作的过程中,我创建了一个清单来强制程序以管理员身份运行,我认为不再需要这样做了。我遇到的问题是我似乎无法删除该要求。

I have.... Changed the project properties to "Create application without a manifest", Added a new item called app.manifest which defaults to asInvoker and changed the properties to use that manifest, renamed any file that has the word manifest in the file name.

我已经......将项目属性更改为“创建没有清单的应用程序”,添加了一个名为 app.manifest 的新项目,默认为 asInvoker 并更改了属性以使用该清单,重命名任何在文档名称。

None of these attempts worked. The program still is running as an administrator. I must be missing something but I'm not sure what.

这些尝试都没有奏效。该程序仍以管理员身份运行。我一定错过了一些东西,但我不确定是什么。

Here are the lines in the app.manifest

这是 app.manifest 中的行

  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
  </requestedPrivileges>

Thanks for the help!!

谢谢您的帮助!!

Gary

加里

采纳答案by Carsten Schütte

Take a look at the app.manifest file in the Properties folder. Remove the following line:

查看 Properties 文件夹中的 app.manifest 文件。删除以下行:

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

Add the following line instead of this:

添加以下行而不是此行:

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

If this did not help, first make sure that you also removed the manifest file from the bin\Debug folder. Simply removing it from the solution does not help, because the file might still be available in the output folder.

如果这没有帮助,请首先确保您还从 bin\Debug 文件夹中删除了清单文件。简单地从解决方案中删除它没有帮助,因为该文件可能仍然在输出文件夹中可用。

That's why I think you should not remove the manifest file from the project, but change it that it works as expected.

这就是为什么我认为您不应该从项目中删除清单文件,而是将其更改为按预期工作。

回答by Ehsan

Although this question is more than an year old now, but i am answering it as it might save one's day.

虽然这个问题现在已经一年多了,但我正在回答它,因为它可能会节省一天的时间。

If you had configured your application to run as administrator mode and now you want to revoke those rights then you need to perform the following steps.

如果您已将应用程序配置为以管理员模式运行,现在您想撤销这些权限,则需要执行以下步骤。

Change

改变

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

To

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

Right click on your project-->Clean your solution-->Rebuildyour solution and that is it.

右键单击您的项目--> 清理您的解决方案--> 重建您的解决方案,就是这样。