Run as administrator: requireAdministrator & ClickOnce + emulating system time

Actually You can't run ClickOnce application with Administrative privileges but there is a little hack, you can start new process with Administrator privileges. In App_Startup:

if (!IsRunAsAdministrator())
{
  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, this application must be run as Administrator.");
  }

  // Shut down the current process
  Application.Current.Shutdown();
}

private bool IsRunAsAdministrator()
{
  var wi = WindowsIdentity.GetCurrent();
  var wp = new WindowsPrincipal(wi);

  return wp.IsInRole(WindowsBuiltInRole.Administrator);
}

Read full article.

But if you want more native and easier solution just ask a user to run Internet Explorer as administrator, ClickOnce tool also will run with admin rights.


Time is a system-wide thing, you can't change it just for your process. The only way to lie about it to your dependencies is to hook the API, using Detours or something similar. Not allowed if you're a lowly user account.

Modifying the time requires the "Change the system time" and/or "Change the time zone" privileges (which the Administrator account is normally given).

And as mentioned by @Chris, admin and ClickOnce aren't compatible.