1

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.

spaleet
  • 838
  • 2
  • 10
  • 23
FEST
  • 813
  • 2
  • 14
  • 37
  • How are you trying to execute the batch file from IIS? It may help if you explain this. – GrahamMc Sep 14 '12 at 11:54
  • I'm really sorry i forgot about that :S i added the code. The comments are tries that i did. – FEST Sep 14 '12 at 13:44
  • You can often use the Event Viewer - Security Log view to see exactly what is failing its permission check. First two things I'd suspect is the user doesn't have the "Log on as Batch Job" Local Security Policy, or rights to execute cmd.exe itself. – Stephen S. Sep 14 '12 at 13:52
  • I have checked the event viewer i there are no warnings or messages about this :S its like it didn't event existed – FEST Sep 14 '12 at 14:41

2 Answers2

0

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.

Derek
  • 8,300
  • 12
  • 56
  • 88
  • hm... it is not really up to me for the solution but we are going to use a schedule to start a webservice that will call the batch. Why do we need the webservice? We need because we want to do some data retrieves from a database. – FEST Sep 14 '12 at 16:20
0

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...

Community
  • 1
  • 1
dmarietta
  • 1,940
  • 3
  • 25
  • 32
  • Thanks for the sharing this but i have done this myself. Since i thought it would be a permission issue i did full control for the application pool entity. I also did the same for requested folders (the ones where the files are). I still get the same problem :S. – FEST Sep 14 '12 at 16:18