c# - Application with elevated privileges is slow to load -
i testing c# wpf program requires elevated privileges, loads without delay if logged on admin, if logged on standard user (99% of time) there delay of 30 seconds before ui appears.
using same elevation code in c# console app , in c# winforms app, there no delay in loading, know code works. so, can explain me why there delay associated wpf; , there workaround?
here code app.xaml.cs ( remainder of project genereated vs2010)
using system; using system.collections.generic; using system.configuration; using system.data; using system.linq; using system.windows; using system.security.principal; using system.diagnostics; using system.reflection; using system.componentmodel; using mynewservicelib; using system.runtime.interopservices; namespace whysoslow { /// <summary> /// interaction logic app.xaml /// </summary> public partial class app : application { protected override void onstartup(startupeventargs e) { base.onstartup(e); if (!isadmin()) { startasadmin(e); application.current.shutdown(); } else { mainwindow = new mainwindow(); mainwindow.sizetocontent = sizetocontent.widthandheight; mainwindow.windowstartuplocation = windowstartuplocation.centerscreen; mainwindow.show(); } } bool isadmin() { windowsidentity id = windowsidentity.getcurrent(); windowsprincipal p = new windowsprincipal(id); return p.isinrole(windowsbuiltinrole.administrator); } private void startasadmin(startupeventargs e) { string[] args = e.args; try { processstartinfo startinfo = new processstartinfo(); startinfo.useshellexecute = true; startinfo.workingdirectory = environment.currentdirectory; uri uri = new uri(assembly.getexecutingassembly().getname().codebase); startinfo.filename = uri.localpath; startinfo.arguments = string.join(" ", args); startinfo.verb = "runas"; process p = process.start(startinfo); } catch (win32exception exception) { messagebox.show(exception.message); } } } }
further info weirdly, if start program cmd prompt running under nt authority\system, there no delay starting ui. after 1 successful start, every further start, whatever prompt, standard user prompt, run administrator, program starts without delay; until is, log off session. after logging on again new (standard user) session, attempts start program result in 30 second delay before showing ui. can think kind of uac bodge microsoft, hindering startup of wpf.
instead of using code, have tried utilizing manifest file? running application admin 1 of things can it.
this might https://msdn.microsoft.com/en-us/library/ms742884.aspx
Comments
Post a Comment