[英]Open Batch file with custom color VB.NET
我正在尝试通过执行以下操作在自定义彩色cmd窗口中打开批处理文件:
Public Class MyUtilities
Shared Sub RunCommandCom(command As String, arguments As String, permanent As Boolean)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
End Sub
End Class
'Inside button click event
Dim OpenCMD
OpenCMD = CreateObject("wscript.shell")
OpenCMD.run("cmd.exe & color 0e & " & My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.bat " & "VARIABLE", vbNormalFocus)
但是,它一直说找不到该文件,当我从头开始删除"cmd.exe & color 0e & "
时,它可以正常工作。 由于我正在使用许多不同的批处理文件,并且不想更改批处理文件本身内部的颜色,因此如何更改它,以使其在运行时具有某种颜色? -批处理文件由许多不同的程序运行,因此为什么我不想更改实际批处理文件本身的颜色,仅当从我的程序中运行时...我无法复制原始文件也一样
您的建议/更正将不胜感激。
我不确定为什么在按钮单击事件中不使用RunCommandCom
。 您只需要:
Dim cmd As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "test.bat")
RunCommandCom("color 0e & " & cmd, "VARIABLE", False)
使用IO.Path.Combine
会为您处理路径定界符(在这种情况下为“ \\”)。
(经测试可正常工作。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.