Hey dude just paste the following code in your application what it will do is if your application does not have admin privileges then it will force application restart in admin mode obviously it will ask first!
public static bool IsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal p = new WindowsPrincipal(id);
return p.IsInRole(WindowsBuiltInRole.Administrator);
}
public static void AqquireAdminMode()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
startInfo.Verb = "runas";
try
{
Process p = Process.Start(startInfo);
}
catch (System.ComponentModel.Win32Exception ex)
{
return;
}
System.Windows.Forms.Application.Exit();
}
and this code should be called in form load event
if(!IsAdmin())
{
AqquireAdminMode();
}
feel free to ask if you still face problems!