简体   繁体   中英

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= * ** password= ** * *


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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM