Link to home
Start Free TrialLog in
Avatar of RayT
RayTFlag for United States of America

asked on

Running RoboCopy from Visual Basic Application

The following visual basic code fails to run.

       Dim srce As String = "C:\Users\ZZZ\Documents\My Great Data\Audio"
        Dim dest As String = "T:\My Great Data\Audio"

        Dim MyProcess As Process

        MyProcess = New Process

            With MyProcess.StartInfo
                .FileName = "C:\Windows\SysWOW64\robocopy.exe"
                .Arguments = srce & " " & dest & " /S /E /M"
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardInput = False
                .RedirectStandardOutput = True
                .RedirectStandardError = True
            End With

            MyProcess.Start()

However running the following PowerShell script works fine

robocopy "C:\Users\ZZZ\Documents\My Great Data\Audio" "t:\My Great Data\Audio" /S /E /M

Why???

I think the problem is the fact that the srce & dest contains spaces.

How can I make this work?
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

quick guess... what if setting:

.UseShellExecute = True

?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RayT

ASKER

Thanks!  I changed the line to

                .Arguments = """" & srce & """" & " " & """" & dest & """" & " /S /E /J"

Everything works great!
Completely subjective, but you can also use Chr(34), instead of double quoting the double quotes:

.Arguments = Chr(34) & srce & Chr(34) & " " & Chr(34) & dest & Chr(34) & " /S /E /M"

Open in new window

Avatar of RayT

ASKER

Thanks.  That makes it more readable.