c# - Giving application elevated UAC -
i have application needs uac elevation.
i have code lets me give application opens twice.. issue..
so here code in form1:
public form1() { initializecomponent(); windowsprincipal pricipal = new windowsprincipal(windowsidentity.getcurrent()); bool hasadministrativeright = pricipal.isinrole(windowsbuiltinrole.administrator); if (!hasadministrativeright) { processstartinfo startinfo = new processstartinfo(); startinfo.useshellexecute = true; startinfo.workingdirectory = environment.currentdirectory; startinfo.filename = application.executablepath; startinfo.verb = "runas"; try { process p = process.start(startinfo); } catch (system.componentmodel.win32exception ex) { return; } } }
and code programs.cs
static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); application.run(new form1()); }
on debugging find out first executes
process p = process.start(startinfo);
which opens application uac elevation dialog , opens application
but goes
application.run(new form1());
in main() , opens application again.
i dont want open app again...
i new there doing wrong , need close uac once open..
thanks
you don't need meddle make sure application runs elevated privileges. can add application manifest instructs windows run app elevated, , uac prompt appear without needing write single line of code.
there's related question answer describes how add manifest here: how can embed application manifest application using vs2008?
Comments
Post a Comment