Mick Jones

Mick Jones

  • NA
  • 1
  • 1.6k

Exe won't run from code

Nov 22 2012 11:58 AM
I have a Windows Desktop application and in one part of it I want to call another application.
I am using ProcessStartInfo to call the exe (Add_schedules.exe).
It works perfectly under Windows XP but not on Windows 7. If I physically right-click on the exe (in Program Files) that the code file is calling and select "Run As" and then pass in the username and password that I am using in the code below, then it works but not when I do it from code behind (as below).
The user credentials I am passing into ProcessStartInfo does have sufficient priveleges to start the application it is calling so it is not insufficeint privelges that is the problem.
I don't even get an exception when I wrap a try/catch around the code.

The Domain,username and password are received from a database via a web service call (I have not included that code). The funny thing is,if I change it to use the credentials of the Administrator of the domain, it works but I am not permitted to do this, it has to be a specific user. It looks like under Windows 7 I can only use ProcessStartInfo when I am using Administrator, but not any other user.

Any replies are appreciated. The code is below.

Edit: Don't suggest using Impersonation as I have tried that already and it only works on Windows 7 if you disable UAC and then reboot (this is not an option).



string loc = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles).ToString();



  ProcessStartInfo startInfo = new ProcessStartInfo(loc + @"\AddSchedules\AddSchedules v1.0.00\Add_schedules.exe");

  startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  startInfo.CreateNoWindow = true;
  startInfo.UseShellExecute = false;
  startInfo.Domain = domainName;
  startInfo.UserName = userName;
  startInfo.Password = s;
  startInfo.Verb = "runas"; 
  Process process = Process.Start(startInfo);
  process.WaitForExit();