以下代码非常简单,可以在控制台应用程序中运行。但由于某种原因,它在 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 中,还有另一个帐户:Default Application Pool ID Changed in IIS 7.5 .也有可能您的池正在使用其他帐户,包括特定于机器的帐户,而不是域帐户。
关于运行批处理文件的 C# 代码在控制台应用程序中工作,但相同的代码在 WCF 服务中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4189800/