I have a method and want to run it with new thread with admin privilege,
[PrincipalPermission(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
void Install()
{
//do some thing
}
I run it in this way,
installerTh = new Thread(new ThreadStart(Install));
installerTh.Name = "Installer";
installerTh.Start();
but it gives me error
System.Security.SecurityException was unhandled
Message=Request for principal permission failed.
Any Idea to show UAC window before running this thread ? (or in the middle of running Process )
UAC is all or nothing. You cannot apply a UAC prompt to a single thread, only to a process. What you need to do is launch your application with a special command line using UAC, and the command line will let you know to start the thread you want. It does not have to be a command line, you could use any type of IPC to let the spawned process know to run the thread. I wrote an answer about launching a process under UAC here.
You might also want to consider getting a code signing certificate so that the UAC dialog won’t keep saying “Unknown” as the publisher.
Update: Based on your comment above, you also cannot apply UAC to your process currently running, only to a new process.