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

2024-06-20

以下代码非常简单,并且可以在控制台应用程序中运行。但由于某种原因,它在 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 服务。

检查与您的应用程序池关联的身份。

据我所知,在 IIS 7 和 6.0 中,这是 NetworkService,它可能有也可能没有批处理文件、SFTP 等的权限。在 7.5 中还有另一个帐户:IIS 7.5 中的默认应用程序池 ID 已更改 http://blogs.iis.net/webdevelopertips/archive/2009/10/02/tip-98-did-you-know-the-default-application-pool-identity-in-iis-7-5-windows-7-changed-from-networkservice-to-apppoolidentity.aspx。您的池也可能正在使用其他帐户,包括特定于计算机的帐户,而不是域帐户。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

运行批处理文件的 C# 代码可以在控制台应用程序中运行,但相同的代码不能在 WCF 服务中运行 的相关文章

随机推荐