Samuel Nicholson
Samuel Nicholson

Reputation: 3629

VB.net using strings in closed quote paths

I'm struggling with how to use defined strings within closed quotes for example (""). I have two text boxes one for a IP or share name and one for a drive letter. When I press my button I want it to map the drive. Below is my code.

  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

I'm struggling with how I can use my driveLetter and drivePath strings within the arguments of

Process.Start("cmd", "/k .....")

Any help would be appreciated as I will need to do this sort of thing quite a lot.

Upvotes: 0

Views: 97

Answers (2)

Simon
Simon

Reputation: 59

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

Upvotes: 1

apros
apros

Reputation: 2878

Use a String's Format method for this purpose:

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

Upvotes: 2

Related Questions