Access denied when I run a .cmd file from c#


I have a web application that is hosted on an IIS7 server on a server computer with windows server 2008, the application consists of executing a .cmd file but it shows me the following error

System.ComponentModel.Win32Exception (0x80004005): Access is denied
   en System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   en System.Diagnostics.Process.Start()
   en System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   en Ted.MNSProject.Reiniciar.Shutdown() en C:\Users\test\Desktop\Soluciones\MNS\Ted.MNS\Ted.MNSProject\Reiniciar.aspx.cs:línea 154
   en Ted.MNSProject.Reiniciar.btnSiReiniciar_Click(Object sender, EventArgs e) en C:\Users\test\Desktop\Soluciones\MNS\Ted.MNS\Ted.MNSProject\Reiniciar.aspx.cs:línea 59

This is my code source

       protected void btnSiReiniciar_Click(object sender, EventArgs e)

                Log2("MNS OK");
            catch (Exception ex)
                Log2("MNS ERROR  " + ex.ToString());


public void Shutdown()
            string pathBAT = "C:\\Users\\pc1\\Desktop\\restartWindows.cmd";

            ProcessStartInfo startInfo = new ProcessStartInfo(pathBAT);

            startInfo.Verb = "runas";


asked on Stack Overflow Jan 14, 2020 by Ivxn • edited Jan 14, 2020 by Ivxn

1 Answer


When you deploy it to IIS, then all code would be executed under "IIS Apppool\" And file like cmd would be reached via your authenticated user like IUSR.

So please try to set your application pool to local system and set anonymous user to application pool identity. enter image description here enter image description here

If you don't want to use localsystem as app pool identity, please try to troubleshooting this with crash dump and process monitor. It will tell us how to grant permission correctly.

answered on Stack Overflow Jan 15, 2020 by Jokies Ding

User contributions licensed under CC BY-SA 3.0