elton73
elton73

Reputation: 473

Running CMD commands in VB with parameters

I'm creating an application in Visual Studio. When the user clicks a button, I want the follow CMD command to be executed:

xcopy /s/y "C:\myfile.txt" "D:\"

I've tried this with Process.Start() but it won't work. The button code is:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Process.Start("CMD", "/C xcopy /s/y "C:\myfile.txt" "D:\"")
End Sub

Does anyone know how I can make this work? I suspect that the problem is caused by the /s/y parameters or quotes in the CMD command.

Upvotes: 1

Views: 7304

Answers (1)

Dai
Dai

Reputation: 155726

Your code won't compile: you need to escape the double-quotes in the string. In VB.NET you escape quotes using double-double quotes:

Process.Start( "CMD", "/C xcopy /s/y ""C:\myfile.txt"" ""D:\""" )

Upvotes: 3

Related Questions