0
我正在使用以下代码从C#运行批处理文件。以下代码是我的Windows服务的一部分。此代码在Windows XP中运行得非常好,但是当我将Windows服务部署到Windows Server 2003操作系统时,它将返回退出代码1(失败)。有人知道我错过了什么吗?我需要给予Windows服务一些特别许可吗?该服务作为本地系统服务安装。无法从Windows服务器2003中的Windows服务运行批处理文件操作系统
ProcessStartInfo psi = new ProcessStartInfo();
//specify the name and arguments to pass to the command prompt
psi.FileName = ConfigurationManager.AppSettings["BatchFilePath"];
psi.Arguments = fileName;
//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("Exit Code" + p.ExitCode);
}
什么是成功返回批处理文件? – Oded 2010-12-02 16:49:09
成功时返回0 – 2010-12-02 16:50:31