2012-01-17 110 views

回答

1

無論最終調用CreateProcess需要通過CREATE_NO_WINDOW進程創建標誌。

該進程是在沒有控制檯窗口的情況下運行的控制檯應用程序。因此,應用程序的控制檯句柄未設置。

究竟如何最好地從腳本實現這一點取決於您使用的腳本語言。

+0

我使用java腳本或VB腳本 – 2012-01-17 10:57:07

0

您可以將其作爲服務的一部分運行,但這需要它具有自我安裝代碼或手動安裝。

另一種方法是編寫一個Windows窗體應用程序,但沒有表格,請執行以下操作:

using System.Windows.Forms; 
using System.Diagnostics; 

namespace WindowsFormsApplication1 
{ 
    static class Program 
    { 
     /// <summary> 
     /// The main entry point for the application. 
     /// </summary> 
     [STAThread] 
     static void Main() 
     { 
      Application.EnableVisualStyles(); 
      Application.SetCompatibleTextRenderingDefault(false); 
      //Application.Run(new Form1()); 

      string ApplicationPath = @"c:\consoleapplication.exe"; 

      // Create a new process object 
      Process ProcessObj = new Process(); 

      // StartInfo contains the startup information of 
      // the new process 
      ProcessObj.StartInfo.FileName = ApplicationPath; 



       // These two optional flags ensure that no DOS window 
       // appears 
       ProcessObj.StartInfo.UseShellExecute = false; 
       ProcessObj.StartInfo.CreateNoWindow = true; 

       // If this option is set the DOS window appears again :-/ 
       // ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

       // This ensures that you get the output from the DOS application 
       ProcessObj.StartInfo.RedirectStandardOutput = true; 

       // Start the process 
       ProcessObj.Start(); 

       // Wait that the process exits 
       ProcessObj.WaitForExit(); 

      } 
     } 
    } 

你可以調用你的腳本這個應用程序。

相關問題