0
我正試圖運行一個批處理文件,其中包含我的資源中的cmd文件。我沒有試圖在任何地方提取它們。我只是想編輯表單中的bat命令並使用我擁有的cmd文件運行它。這可能嗎?如何從vb資源運行bat文件和自定義cmd文件?
我正試圖運行一個批處理文件,其中包含我的資源中的cmd文件。我沒有試圖在任何地方提取它們。我只是想編輯表單中的bat命令並使用我擁有的cmd文件運行它。這可能嗎?如何從vb資源運行bat文件和自定義cmd文件?
無法先運行.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
好的謝謝。我想這樣做很好。 – 2012-04-15 07:44:01