0

From my C# application I want to start another application that requires admin privilleges and has manifest that ensures it. My part of code:

                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(@"MyLauncher.exe");
                startInfo.Arguments = "/a"; 
                startInfo.UseShellExecute = true;  
                startInfo.Verb = "runas";
                System.Diagnostics.Process p = System.Diagnostics.Process.Start(startInfo);
                Thread.Sleep(5000);
                Current.Shutdown();

Unfortunatelly sometimes application start smoothly but from time to time only UAC dialog appears but the application does not start. I tried different startup settings but no luck.

iljon
  • 398
  • 2
  • 16
  • Ensure that this application runs with administrator privileges to begin with, then it should be able to open the other application with the equivalent privileges. – ManoDestra Jul 07 '16 at 16:44
  • is the calling process itself always elevated? – Cee McSharpface Jul 07 '16 at 16:44
  • The process method in C# is just as reliable as starting an application from a shortcut. Try starting program from a shortcut and see if same results occur. – jdweng Jul 07 '16 at 16:45
  • The chronic problem is assuming that it has something to do with your code but it is actually the program you start that immediately bombs. Albeit that not setting the startInfo.WorkingDirectory is a pretty good way to trigger a bug. Use p.WaitForExit() and then look at p.ExitCode and you'll know a little bit more. – Hans Passant Jul 07 '16 at 16:46
  • "but from time to time only UAC dialog appears but the application does not start" -- Are you saying that the app isn't starting because there's a UAC prompt there, and you want the app to start programmatically even when there is no human there to click "yes" on the UAC prompt? – Quantic Jul 07 '16 at 16:53
  • @Quantic. UAC Dialog appears, user clicks yes and that is all. It looks like that the program does not work on. But this is not a rule, sometimes the program works correctly. – iljon Jul 07 '16 at 16:58
  • When the UAC dialog appears, then the invoking code will already be past the `Process.Start` call, and it is out of its hands. If you have the source of the called assembly, add diagnostics there. Also look into the security event log. – Cee McSharpface Jul 07 '16 at 17:07
  • possible duplicate of http://stackoverflow.com/questions/38242800/debugging-code-after-process-start-in-visual-studio – Cee McSharpface Jul 07 '16 at 19:41

0 Answers0