0

我有一个旨在启动多个控制台应用程序的 Windows 服务。控制台应用程序将写入物理日志文件以及文件系统操作。

当服务启动控制台时,它们无法访问文件系统,日志文件中也不会出现任何内容。

当我通过双击可执行文件手动启动控制台时,它们写入日志文件没有问题。

我尝试在本地系统、本地服务、网络服务、本地管理员帐户甚至我自己的登录凭据下运行该服务:

这是启动进程的代码:

Process p = new Process();
p.StartInfo.FileName = agent.AgentLocation; /// Physical path to executable
p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
4

1 回答 1

0

更新:

问题原来是需要设置工作目录如下:

Process p = new Process(); 
p.StartInfo.FileName = agent.AgentLocation; /// Physical path to executable 
p.StartInfo.WorkingDirectory = agent.AgentLocation.Substring(0, agent.AgentLocation.LastIndexOf("\\") + 1);
p.StartInfo.CreateNoWindow = true; 
p.StartInfo.ErrorDialog = false; 
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
p.Start(); 
于 2012-05-22T19:57:56.660 回答