【问题标题】:System.Diagnostics.Process.Start() [closed]System.Diagnostics.Process.Start() [关闭]
【发布时间】:2010-12-22 17:55:56
【问题描述】:

System.Diagnostics.Process.Start(@"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe") 在 Windows 服务的计时器事件中执行时不起作用?

【问题讨论】:

  • 也许您想详细说明它是如何“不工作”的。例如。是否抛出异常?

标签: c#


【解决方案1】:

此代码可能会帮助您的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);
            }
        }
    }
}

【讨论】:

    【解决方案2】:

    Windows 服务在用户的交互式会话之外运行,因此尽管可以执行进程,但您不应期望打开一个新窗口(在您的情况下是 acrobat 阅读器的实例)。

    此外,您通常会根据服务运行的用户身份对您可以做什么或不可以做什么有安全限制。

    【讨论】:

    • 我开始出现以下错误:应用程序未能正确初始化 (0xc0000142)
    【解决方案3】:

    查看these posts 和周围的许多其他人。 Windows 服务通常不用于交互性,并且会根据其运行身份而存在各种安全问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多