Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't have any Windows 8 installation available to test this on, but I encountered a similar problem when requiring admin privileges in a Click Once deployment (where you are not allowed to use the manifest).</p> <p>Solved it by having the application do a check at startup if it is running as admin or not, if it's not running as admin it restarts itself as admin.</p> <p>Here is the code (slightly modified) that I use:</p> <pre><code>public static bool IsRunningAsAdministrator() { var wi = WindowsIdentity.GetCurrent(); var wp = new WindowsPrincipal(wi); return wp.IsInRole(WindowsBuiltInRole.Administrator); } public static void StartAsAdmin(StartupEventArgs e) { if (IsRunningAsAdministrator()) return; // 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.GetEntryAssembly().CodeBase); // The following properties run the new process as administrator processInfo.UseShellExecute = true; processInfo.Verb = "runas"; // Start the new process Process.Start(processInfo); // Shut down the current process Application.Current.Shutdown(); } </code></pre> <p><strong>Update after testing on a lot of machines:</strong> One problem I bumped into with this solution is that anti-virus software often sees this as suspicious behaviour and blocks the startup.</p> <p>I ended up changing the installer + auto updating from Click Once to <a href="http://wix.sourceforge.net/" rel="nofollow">WiX Toolset</a> + <a href="https://github.com/synhershko/nappupdate" rel="nofollow">NAppUpdate</a> and run with <code>requestedExecutionLevel="requireAdministrator"</code> instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload