2012-04-15 162 views

回答

2

無法先運行.cmd.bat文件,而無需先將其保存到磁盤。它必須在cmd.exe的閱讀和解釋。您必須先將其保存到磁盤並從那裏運行。

保存之後,您可以使用System.Diagnostics.Process運行它。從鏈接的VB.Net示例:

Imports System 
Imports System.Diagnostics 
Imports System.ComponentModel 

Namespace MyProcessSample 
Class MyProcess 

    Public Shared Sub Main() 
    Dim myProcess As New Process() 

     Try    ' Get the path that stores user documents. 
     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 e As Exception 
     Console.WriteLine((e.Message)) 
     End Try 
    End Sub 'Main 
    End Class 
End Namespace 
+0

好的謝謝。我想這樣做很好。 – 2012-04-15 07:44:01