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

前端 未结 11 1639
暗喜
暗喜 2020-12-07 15:33

So I was writing an application that requires access to the registry. I had not touched any build settings, wanting to get the thing working before I added the other touches

相关标签:
11条回答
  • 2020-12-07 16:06

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

    0 讨论(0)
  • 2020-12-07 16:06

    For those who use uncheck "Enable ClickOnce security settings" can't work, to try the method I find.

    First, leave your app.manifest requestedExecutionLevel item as is:

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

    And then you edit your Program.cs file like this:

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

    restruct main method like:

        static void Main()
            {
                var wi = WindowsIdentity.GetCurrent();
                var wp = new WindowsPrincipal(wi);
    
                bool runAsAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator);
    
                if (!runAsAdmin)
                {
                    // It is not possible to launch a ClickOnce app as administrator directly,
                    // so instead we launch the app as administrator in a new process.
                    var processInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().CodeBase);
    
                    // The following properties run the new process as administrator
                    processInfo.UseShellExecute = true;
                    processInfo.Verb = "runas";
    
                    // Start the new process
                    try
                    {
                        Process.Start(processInfo);
                    }
                    catch (Exception)
                    {
                        // The user did not allow the application to run as administrator
                        MessageBox.Show("Sorry, but I don't seem to be able to start " + 
                           "this program with administrator rights!");
                    }
    
                    // Shut down the current process
                    Application.Exit();
                }
                else
                {
                    // We are running as administrator
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
            }
    

    It works on Windows 10 and Visual Studio 2019!

    0 讨论(0)
  • 2020-12-07 16:10

    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).

    0 讨论(0)
  • 2020-12-07 16:11

    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. :-)

    0 讨论(0)
  • 2020-12-07 16:12

    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:

    enter image description here

    0 讨论(0)
提交回复
热议问题