繁体   English   中英

运行批处理文件的C#代码在控制台应用程序中工作,但相同的代码在WCF服务中不起作用

[英]C# code to run a batch file works in console application, but same code doesnt work in WCF Service

以下代码非常简单,适用于控制台应用程序。 但由于某种原因,它在WCF服务中不起作用。 具有批处理文件的目录具有完全权限。 有人能帮我吗? 我错过了什么?

    try
        {
            ProcessStartInfo psi = new ProcessStartInfo();

            //specify the name and the arguements you want to pass
            psi.FileName = ConfigurationManager.AppSettings["BatchFileLocation"];
            psi.Arguments = filePath; 

            //Create new process and set the starting information
            Process p = new Process();
            p.StartInfo = psi;

            //Set this so that you can tell when the process has completed
            p.EnableRaisingEvents = true;

            p.Start();

            //wait until the process has completed
            while (!p.HasExited)
            {
                System.Threading.Thread.Sleep(1000);
            }

            //check to see what the exit code was
            if (p.ExitCode != 0)
            {
                logger.Write(p.ExitCode);
            }
        }
        catch (Exception ex)
        {
            logger.Write(ex.Message);
        }

我假设这是一个IIS托管的WCF服务。

检查与应用程序池关联的Identity。

在IIS 7和6.0中,据我所知,这是NetworkService,它可能拥有或不拥有批处理文件,SFTP等权限。在7.5中还有另一个帐户: IIS 7.5中更改了默认应用程序池ID 您的池也可能正在使用其他帐户,包括特定于计算机的帐户,而不是域帐户。

暂无
暂无

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

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