0

I want to call an .exe that is on my Windows machine. I publish the site to a folder inside "C:\inetpub\wwwroot" and can call the API from outside. Problem is when I run the code from VS on IIS Express the exit code of the process is 0 and the exe is executed successfully, but when I call the Action Result from outside and it runs on the IIS the status code is 1 and there is obviously a problem with this process calling: Here is my code:

public async Task<ActionResult> url2img(string url)
    {
        Process proc = new Process();
        proc.StartInfo.FileName = @"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe";
        proc.StartInfo.Arguments = $"--encoding utf-8 \"{url}\" {FilePath}";
        proc.Start();
        proc.WaitForExit();

        object oJSON = new { procStatusCode = proc.ExitCode };

        proc.Close();

        return Json(oJSON, JsonRequestBehavior.AllowGet);
    }

I found this thread, and read the proposed answer by the OP, but I cannot find "load windows profile" in my IIS and also I am not sure if this is the same issue as his? Any help?

enter image description here

nmrlqa4
  • 659
  • 1
  • 9
  • 32

3 Answers3

1

I ran the sample and ExitCode is no longer valid after calling Close(). Hence the invalid operation.

Brian Clink
  • 297
  • 2
  • 17
0

I think, your iis user does not have privileges. may be you want to examine this link:Foo.cmd won't output lines in process (on website)

Esat ARSLAN
  • 119
  • 7
  • I already answered my question and it works, but thanks! I will mark it tomorrow, when I have the right. – nmrlqa4 Oct 30 '18 at 09:03
-1

I had to set the Identity of the DefaultAppPool to LocalSystem

enter image description here

nmrlqa4
  • 659
  • 1
  • 9
  • 32
  • 1
    Just because it works doesn't mean it's a good idea. Running iis as Localsystem is very bad practise, you should configure your app pool identity with nessersary permissions instead. – MisterSmith Nov 04 '18 at 12:29