VB.net在封闭的引用路径中使用字符串

时间:2013-10-02 15:04:38

标签: vb.net

我正在努力解决如何在封闭引号中使用已定义的字符串(例如“(”))。我有两个文本框,一个用于IP或共享名称,另一个用于驱动器号。当我按下我的按钮时,我希望它映射驱动器。以下是我的代码。

  Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim drivePath As String = TextBox1.Text
        Dim driveLetter As String = TextBox2.Text

        Process.Start("cmd", "/k net use driveLetter drivePath")

    End Sub

我正在努力如何在

的参数中使用我的driveLetter和drivePath字符串
Process.Start("cmd", "/k .....")

任何帮助都会受到赞赏,因为我需要做很多这样的事情。

2 个答案:

答案 0 :(得分:2)

为此目的使用字符串的Format方法:

Process.Start("cmd", String.Format("/k net use {0} {1}", driveLetter, drivePath))

答案 1 :(得分:1)

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click        

    Dim drivePath As String = TextBox1.Text
    Dim driveLetter As String = TextBox2.Text

    Process.Start("cmd", "/k net use " & driveLetter & " " & drivePath)
End Sub