Uac avec c# Programmation
bonjour ,
je doit utiliser une application , qui va avoir besoin des droits sous c#
j'ai reussi en utilisant ce code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| private void RunElevated(string fileName)
{
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.Verb = "runas";
processInfo.FileName = fileName;
try
{
Process.Start(processInfo);
}
catch (Win32Exception)
{
//Do nothing. Probably the user canceled the UAC window
}
} |
et dans mon formload :
Code:
1 2 3 4 5 6 7 8 9 10
| WindowsPrincipal pricipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
bool hasAdministrativeRight = pricipal.IsInRole(WindowsBuiltInRole.Administrator);
if (!hasAdministrativeRight)
{
RunElevated(Application.ExecutablePath);
this.Close();
} |
du coup toute mon application tourne avec les droits d'admin .
est-ce une bonne méthode?
ce qui m'embete c'est le fait que l'application s'ouvre 2 fois a cause du application.executablepath .
n'y a t-il pas moyen autrement ( hors manifest ) ?
merci