开发者

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

开发者 https://www.devze.com 2023-01-25 01:05 出处:网络
This following code is pretty simple and it works in a Console Application. But for some reason it does not work in a WCF Service. The directory which has the batch file has full permissions. Can some

This following code is pretty simple and it works in a Console Application. But for some reason it does not work in a WCF Service. The directory which has the batch file has full permissions. Can someone help me? What am I missing?

    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
            Proce开发者_StackOverflow社区ss 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);
        }


I assume this an IIS Hosted WCF Service.

Check the Identity associated with your application pool.

In IIS 7, and 6.0 to the best of my knowledge, this is the NetworkService, which may or may not have rights to the Batch file, SFTP, etc. In 7.5 there is another account: Default Application Pool ID Changed in IIS 7.5. It is also possible that your pool is using some other account, including a machine specific one, and not a domain account.

0

精彩评论

暂无评论...
验证码 换一张
取 消