【发布时间】:2016-03-08 04:49:12
【问题描述】:
我在尝试从计划任务调用的程序中调用程序时收到此错误。
private static void CallProgram(int jobID, int productID)
{
DataTable dtProduct = GetProductInformation(productID);
try
{
// 1
// Initialize process information.
//
ProcessStartInfo p = new ProcessStartInfo();
p.WorkingDirectory = string.Format(@"{0}", dtProduct.Rows[0]["ProgramDirectory"].ToString());
p.FileName = dtProduct.Rows[0]["ProgramName"].ToString();
// 2
// add arguements
string[] args = { jobID.ToString() };
p.Arguments = String.Join(" ", args);
p.UseShellExecute = true;
p.Verb = "runas";
//p.WindowStyle = ProcessWindowStyle.Hidden;
p.CreateNoWindow = true;
// 3.
// Start process and wait for it to exit
//
Process x = Process.Start(p);
//x.WaitForExit();
}
catch (Exception ex)
{
string function = MethodBase.GetCurrentMethod().Name;
ErrorHandling(function, ex.Message, ex.StackTrace);
throw;
}
}
我目前有一个执行此操作的 Windows 服务。但是我发现它有时会挂起。我已经构建了一个控制台应用程序,该应用程序的功能与该服务的功能完全相同。我的想法是将它放在任务调度程序上,以便它按设定的时间间隔运行。类似于windows服务。但是,当我从调度程序运行程序时,我收到以下错误
WorkOnQueue 错误:此操作需要交互式窗口 站堆栈跟踪:在 System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) 在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo) 在 RenkimAutomation.Program.CallProgram(Int32 jobID, Int32 产品 ID)在 RenkimAutomation.Program.WorkOnQueue() 机器名称: 产品服务时间戳:2016 年 3 月 7 日下午 6:11:04
我不知道如何解决这个错误。请帮忙
【问题讨论】:
-
你可以尝试在管理员模式下运行你的应用程序
-
计划任务设置为以最高权限运行。
-
我现在无法验证它,但我认为
WindowStyle不是您想要的ProcessStartInfo上的参数。查看CreateNoWindow。 -
@object88 我修改了程序以使用 CreateNoWindow = true。但是我仍然收到错误。