在IIS服务器上运行bat文件

时间:2012-09-14 10:15:05

标签: c# asp.net iis batch-file

我正在尝试使用iis版本6.1 SP1在Windows Server 2008 R2 64bit上运行.bat文件。 在我的本地机器上一切顺利但在服务器上没有任何反应,除了创建的进程(cms.exe * 32)。

从我的搜索中,主要问题是权限。我在几个地方读到,出于安全原因,iis默认阻止访问批处理文件。我确实理解了这个问题,但在我的情况下,没有安全问题,所以我仍想运行我的文件。


我发现通过实施模仿传递的解决方案意味着:

1-更改web.config     - > identity impersonate =“true”

2-更改iis站点身份验证     - >启用ASP.NET模拟

3-授予文件和文件夹的权限

4-甚至尝试了第1步的不同版本     - > identity impersonate =“true”userName = * ** 密码= ** * *


授予IIS用户权限:

1-设置允许服务与IIS Admin Service上的桌面交互


要调用批处理,请在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;
        }

还应该注意的是,我试图执行其他文件,包括.exe文件,但没有结果。

非常感谢所描述步骤的任何建议,帮助或更正。

2 个答案:

答案 0 :(得分:0)

这可能不是您所寻求的,但可能有所帮助。我建议你在服务器上创建一个计划任务来运行BAT文件,你可以设置用户权限,然后安排你希望运行它。

希望这有帮助。

答案 1 :(得分:0)

下面是另一篇Stackoverflow文章的链接,该文章似乎对同一问题有非常详细的回应。

IIS7 does not start my Exe file...