2

I can find a lot of threads discussing Process.Start but none which sound like mine. The code below has been working for years on Windows Server 2003 & 2008. I'm now trying to install the same application on 2012 but although "My.exe" starts, Process.Start itself hangs - so "Started" is never logged. Can anybody suggest what the issue might be?

Many thanks in advance,

Michael

ProcessStartInfo psi = new ProcessStartInfo("C:\\My.exe");
psi.UseShellExecute = false;
psi.LoadUserProfile = false;
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.ErrorDialog = false;
if (Environment.OSVersion.Version.Major >= 6) psi.Verb = "runas";
psi.Arguments = "\"MyArgs\"";
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
_logger.Info("Starting");
_process = Process.Start(psi);
_logger.Info("Started");

2 Answers2

0

Possibly the same thing as this?

Also assuming that

"C:\My.exe"

is a typo = "C:\\My.exe" or @"C:\My.exe"

Community
  • 1
  • 1
jeoffman
  • 1,303
  • 10
  • 23
  • Sorry, yes that was a typo. – user3306282 Sep 18 '14 at 13:47
  • The link there, if I understand it correctly, is a problem where WaitForExit hangs. I'm not using that method and couldn't use it - as I'd need a Process object first, which I'm not getting as Process.Start never returns. – user3306282 Sep 18 '14 at 13:49
  • I dumped your sample into a WinForm app and ran it under a Server 2012 VM - replaced My.exe with cmd.exe and removed the Argument. The code works both as administrator and a normal user - maybe there is a problem with the "My.exe" program? – jeoffman Sep 18 '14 at 14:02
0

I believe that the "runas" verb to interactively demand administrative permissions only works when ProcessStartInfo.UseShellExecute=true, assuming that the app does run interactively and you want the use to be prompted to approve an adminstrative action. If not you might look into demanding the permissions from a manifest.

Have you tried wrapping your _process = Process.Start(psi) in a try/catch and logging any exceptions?

Have you tried dropping this code into a console app with both of the RedirectStandard ... to false to see what happens?

Miniver Cheevy
  • 1,667
  • 2
  • 14
  • 20