简体   繁体   English

在 IIS 服务器上运行 bat 文件

[英]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.我正在尝试在带有 iis 版本 6.1 SP1 的 Windows Server 2008 R2 64 位上运行 .bat 文件。 On my local machine everything goes well but on server nothing happens, except for a process that gets created (cms.exe *32).在我的本地机器上一切顺利,但在服务器上没有任何反应,除了创建的进程(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.我在几个地方读到,出于安全原因,默认情况下的 iis 会阻止对批处理文件的访问。 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" 1- 更改 web.config -> 身份 impersonate="true"

2- change iis site authentication -> ASP.NET Impersonation Enabled 2- 更改 iis 站点身份验证 -> ASP.NET Impersonation Enabled

3- give permissions to the file and folders 3- 授予文件和文件夹的权限

4- even tried a different version of step 1 -> identity impersonate="true" userName= * ** 4- 甚至尝试了不同版本的步骤 1 -> identity impersonate="true" userName= * ** password=密码= ** * * ** * *


Give permissions to the IIS User:授予 IIS 用户权限:

1- set allow service to interact with desktop on the IIS Admin Service 1- 设置允许服务与 IIS 管理服务上的桌面交互


To call the batch i use the following code in c#:要调用批处理,我在 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.还应该注意的是,我尝试执行其他文件,包括 .exe 文件,但没有结果。

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.我建议您在服务器上创建一个计划任务来运行 BAT 文件,您可以设置用户权限,然后安排您希望何时运行它。

Hope this helps.希望这可以帮助。

Below is a link to another Stackoverflow article that appears to have a very detailed response to the same problem.下面是另一篇 Stackoverflow 文章的链接,该文章似乎对同一问题有非常详细的回应。

IIS7 does not start my Exe file... IIS7 不启动我的 Exe 文件...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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