【发布时间】:2010-12-22 17:55:56
【问题描述】:
System.Diagnostics.Process.Start(@"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe") 在 Windows 服务的计时器事件中执行时不起作用?
【问题讨论】:
-
也许您想详细说明它是如何“不工作”的。例如。是否抛出异常?
标签: c#
System.Diagnostics.Process.Start(@"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe") 在 Windows 服务的计时器事件中执行时不起作用?
【问题讨论】:
标签: c#
此代码可能会帮助您的System.Diagnostics.Process.Start Class
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
public static void Main()
{
Process myProcess = new Process();
try
{
myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
// This code assumes the process you are starting will terminate itself.
// Given that is is started without a window so you cannot terminate it
// on the desktop, it must terminate itself or you can do it programmatically
// from this application using the Kill method.
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
【讨论】:
Windows 服务在用户的交互式会话之外运行,因此尽管可以执行进程,但您不应期望打开一个新窗口(在您的情况下是 acrobat 阅读器的实例)。
此外,您通常会根据服务运行的用户身份对您可以做什么或不可以做什么有安全限制。
【讨论】: