“ClickOnce does not support the request execution level 'requireAdministrator.'”

时间秒杀一切 提交于 2019-11-28 03:37:58

Edit: This comment gives a good answer, too.

Click once appears to get enabled whenever you click "Publish", whether you want it to or not! If you are using "requireAdministrator" then it appears that you cannot use ClickOnce, and therefore cannot "Publish" your project.


Original:

Turns out that under the Security tab, "Enable ClickOnce security settings" was checked. Even though I didn't check it. Anyway, unchecking that stopped ClickOnce giving me errors. That took a while to find...

I know this an old question but I came here two years later so:

You can disable the ClicKOnce from the Security tab on project properites to help the issue; see below:

If you ever use the publishing wizard, or 'Publish Now', the click-once checkbox gets automatically selected...

Tyler C

I know this is old but I stumbled across it looking for answers. In my case, I AM using the publish function and I need to keep using it. I also need access to admin capabilities. So for that reason, none of the above answers worked for me.

I ended up adding a method to the very start of my application that checks if it's being run as an administrator and if it isn't, relaunch itself as an admin. To do this, you need the following references added.

using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;

Then you will need to put this somewhere that your main method has handy access to. I'm using WPF so I added it to MainWindow.xaml.cs but you can add it anywhere early on in your code. Just remember to add "static" to these methods should you need it.

private void AdminRelauncher()
{
    if (!IsRunAsAdmin())
    {
        ProcessStartInfo proc = new ProcessStartInfo();
        proc.UseShellExecute = true;
        proc.WorkingDirectory = Environment.CurrentDirectory;
        proc.FileName = Assembly.GetEntryAssembly().CodeBase;

        proc.Verb = "runas";

        try
        {
            Process.Start(proc);
            Application.Current.Shutdown();
        }
        catch(Exception ex)
        {
            Console.WriteLine("This program must be run as an administrator! \n\n" + ex.ToString());
        }
    }
}

private bool IsRunAsAdmin()
{
    try
    {
        WindowsIdentity id = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(id);
        return principal.IsInRole(WindowsBuiltInRole.Administrator);
    }
    catch (Exception)
    {
        return false;
    }
}

Lastly, at the start of your program, add a reference to the method. In my case, I added it to MainWindow but adding it to Main works too.

public MainWindow()
{
    InitializeComponent();
    AdminRelauncher(); //This is the only important line here, add it to a place it gets run early on.
}

Hope this helps!

Take a look in your app.Manifest file and you'll see this:

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

There's instructions there in the comments, but just deleting the "requireAdministrator" and insert this in is place solved the problem for me:

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

This action can be achieved by selecting "Enable ClickOnce security settings" (since it cannot be "unchecked" during a Publish, as stated) and then by selecting "This is a partial trust application". "Local Intranet" will be automatically selected in the drop-down menu which is perfectly fine.

Save your changes, Publish the application, done-skis. :-)

I have the same problem s I resolve it by unchecking the "Enable ClickOnce security settings" To Find this option in Visual Studio Right Click on your Project ==>properties==>Select Security==> Enable ClickOnce security settings (This option was already checked so I unchecked it and my problem get resolved).

Here is the code snippet for VB.NET

If Not New WindowsPrincipal(WindowsIdentity.GetCurrent).IsInRole(WindowsBuiltInRole.Administrator) Then
            Process.Start(New ProcessStartInfo With { _
                                                     .UseShellExecute = True, _
                                                     .WorkingDirectory = Environment.CurrentDirectory, _
                                                     .FileName = Assembly.GetEntryAssembly.CodeBase, _
                                                     .Verb = "runas"})

EDIT: But if you deploy in this way, some AV-Software blocks your code.

just

Imports System.security

and U will get no error and your application will be run as admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!