我正在尝试使用我的资源中的cmd文件运行批处理文件。我不想在任何地方提取它们。我只想在表单中编辑bat命令并使用我拥有的cmd文件运行它。这可能吗?
答案 0 :(得分: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