Reputation: 29
I have created a Web API for installing the latest version of exe using Web API and hosted via IIS Server.
The process is Downloading -> Closing -> Installing Exe via CLI.
The downloading process is working fine.
While closing the running exe exception caught "Access is denied."
Following is the code block I am using to close the running exe.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebGrease;
namespace API.Controllers
{
public class TestController : ApiController
{
public string Get()
{
foreach (Process p in Process.GetProcessesByName("APPLICATION NAME"))
{
try
{
p.Kill();
p.WaitForExit();
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
return "Aborted";
}
}
}
While debugging the same this code block is working fine but when testing on another computer it says "Access is Denied".I guess this issue is related to Windows Authentication.
Upvotes: 0
Views: 830
Reputation: 7522
Debugging the above code will take the current logged window account as the credential to run the WebAPI. However, some other built-in system account will be used when the project is hosted in the IIS. This is commonly determined by the IIS application pool identity.
Although granting the administrative permission to IIS is risky for website security, at least this could solve your problem.
Feel free to let me know if the problem still exists.
Upvotes: 1