我正在尝试使用资源中的 cmd 文件运行批处理文件。我不想在任何地方提取它们。我只是想编辑表单中的 bat 命令并使用我拥有的 cmd 文件运行它。这可能吗?
问问题
1578 次
1 回答
3
如果不先将其保存到磁盘,就无法运行.cmd
or文件。.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-15T07:29:24.417 回答