将vb参数传递给批处理文件

时间:2015-09-23 17:02:49

标签: vb.net batch-file

我正在尝试执行下一批文件:

route ADD 131.1.0.0 MASK 255.255.0.0 191.168.0.136
pause

但是,我想通过visual basic app制作ip地址变量。

现在我尝试了下一步:

Public Class Form1
    Dim a

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        a = (TextBox1.Text)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim objWshShell
        objWshShell = CreateObject("Wscript.Shell")
        objWshShell.run(Chr(34) & "C:\NAT\RouteHCM.bat" & Chr(34) & a, 1)

    End Sub
End Class

如何添加更多变量,是否可以制作此批处理脚本(直接在Visual Basic中添加路径)?

1 个答案:

答案 0 :(得分:1)

这样:

  • 假设您在表单上有TextBox1,TextBox2,TextBox3

  • 使用以下内容替换整个班级:

Imports System.Diagnostics

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        With New Process()
            .StartInfo.UseShellExecute = False
            .StartInfo.FileName = "route"
            .StartInfo.Arguments = String.Format("-p add {0} mask {1} {2}",
                                                 TextBox1.Text,
                                                 TextBox2.Text,
                                                 TextBox3.Text)
            .StartInfo.RedirectStandardOutput = True
            .StartInfo.StandardOutputEncoding = Text.Encoding.ASCII
            .Start()
        End With
    End Sub
End Class

如果您查看String.Format()ProcessStartInfo的帮助,您就会明白这一点。 (我也在那里学习东西。)