'Running bat file on IIS server

I'm trying to run a .bat file on a windows server 2008 R2 64bit with IIS version 6.1 SP1. On my local machine everything goes well but on server nothing happens, except for a process that gets created (cms.exe *32).

From my search the main problem is permissions. I read in several places that IIS for default blocks access to batch files for security reasons. I do understand the problem but in my case there would be no security issue so i would like to still run my file.


The solutions i found passed by implementing impersonation which means:

  1. Change web.config -> identity impersonate="true"

  2. Change IIS Site Authentication -> ASP.NET Impersonation Enabled

  3. Give permissions to the file and folders

  4. Even tried a different version of step 1 -> identity impersonate="true" userName=**********


Give permissions to the IIS User:

  1. set allow service to interact with desktop on the IIS Admin Service

To call the batch i use the following code in C#:

private void StartPervasive(string npu) 
{
   
    try 
    {
       
        ProcessStartInfo startInfo = new ProcessStartInfo(ConfigurationManager.AppSettings.Get("PervasivePath"));
    
        //startInfo.UseShellExecute = true;
        //startInfo.WorkingDirectory = ConfigurationManager.AppSettings.Get("PervasiveWorkingPath");
        //startInfo.WindowStyle = ProcessWindowStyle.Normal;
        //startInfo.RedirectStandardInput = true;
        //startInfo.RedirectStandardError = true;
        //startInfo.RedirectStandardOutput = true;
    
        //startInfo.FileName = ConfigurationManager.AppSettings.Get("PervasivePath");
     
        startInfo.Arguments = npu;
        Process myProcess = Process.Start(startInfo);
     
        //StreamReader sr = File.OpenText(ConfigurationManager.AppSettings.Get("PervasivePath"));
        //StreamWriter sw = myProcess.StandardInput;
    
        //while (sr.Peek() != -1)
        //{
        //    string readed = sr.ReadLine();
        //    readed = readed.Replace("%1", npu);
        //    sw.WriteLine(readed + Environment.NewLine);
        //}

        //myProcess.WaitForExit();
        //myProcess.Close();
    
   } 
   catch (Exception ex) 
   {
     throw ex;
   }
}

It should also be of note that i tried to execute other files including .exe files but with no results.

Would appreciate any advice, help and or corrections to the steps described.



Solution 1:[1]

This may not be what your looking for, but may help. I would suggest you create a Scheduled Task on the Server to run the BAT file, you can set the User Permissions and then schedule when you wish to run it.

Hope this helps.

Solution 2:[2]

Below is a link to another Stackoverflow article that appears to have a very detailed response to the same problem.

IIS7 does not start my Exe file...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Derek
Solution 2 Community