1

I created a wcf service and host in IIS. Inside it has a method to execute program on the server-side by invoking from the client. It doesn't seem to work. Nothing happens when the method is called.

System.Diagnostics.Process.Start(@"C:\MtbKill.bat");

Above is the code that doesn't work. I also tried to some process.

Process[] process = Process.GetProcessesByName("Mtb");
foreach (var item in process)
{
    try
    {
        item.Kill();
    }
    catch
    {
    }
}

It is not working too. I'm very confused that is it concerned with authorization? Because I have tried such to create folder, it doesn't have any problem.

Solution

I have searched many sources of related problems. Here is what I found Access is denied at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

Community
  • 1
  • 1
  • Please see [ask]. In particular, what do you mean, "it doesn't work"? – John Saunders Jan 05 '15 at 04:56
  • 1
    Does the identity for the AppPool for your IIS App have access to c:\ ? –  Jan 05 '15 at 05:01
  • I don't know how to check it. Sorry, I am newbie for this. I will try moving path to another drive. – user3386894 Jan 05 '15 at 05:41
  • @user3386894 Just check if [Impersonating](http://support.microsoft.com/kb/306158) the process invocation code can help you. – Siva Gopal Jan 05 '15 at 05:48
  • Thank you Micky Duncan. I found this is how to identify access http://www.iis.net/learn/manage/configuring-security/application-pool-identities – user3386894 Jan 05 '15 at 06:16
  • @user3386894: if you found the solution, please answer to your own question, instead of editing the question. This will allows you to flag the post as answered and help future readers to find the solution – Steve B Jan 05 '15 at 08:08

3 Answers3

3

To run a batch file you must run "cmd.exe" with argument "/c" and the name of the file.

System.Diagnostics.Process.Start(@"cmd.exe /c C:\MtbKill.bat");
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

Solution

Sorry for editing instead of posting the answer

Here is a related problem link that solves my problem.

Access is denied at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)

Thank you for all help.

Community
  • 1
  • 1
0

This is how i start a process:

try{
 Process.Start("osk.exe", "/C");
} catch(exception ex)
{
WriteLog("Error: Onscreen keyboard could not start.", ex);
}

this is how i kill a process:

    try
    {
      Process[] processlist = Process.GetProcesses();
      foreach (Process theprocess in processlist)
      {
        if (theprocess.ProcessName == "osk")
        {
          theprocess.Kill();
        }
      }
    }
    catch (Exception ex)
    {
      WriteLog("Error: KillKeyBoardProcess", ex);
    }

Hope it helps.

Max Mazur
  • 1,188
  • 1
  • 13
  • 22