2010-12-22 33 views
-1

System.Diagnostics.Process.Start(@"C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe")從計時器執行時不起作用Windows服務的事件?System.Diagnostics.Process.Start()

+4

也許你想詳細說明它是如何「不起作用」的。例如。是拋出的異常? – Reddog 2010-12-22 09:52:03

回答

3

此代碼可能會幫助您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 reader的實例)。

此外,基於運行服務的用戶,您經常會對您可以或不可以執行的操作有安全限制。

+0

我開始以下錯誤:應用程序未能正確初始化(0xc0000142) – 2010-12-22 09:59:52

0

退房theseposts和許多其他地方。 Windows服務通常不用於交互,並且會根據運行的用戶而具有各種安全問題。

相關問題