Click here to Skip to main content
15,917,177 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi there, I am trying to write a simple GUI for Robocopy. In the code below I can get the CMD window to appear - very briefly ... then disappear -- essentially I think my code is "working" except it's not getting my variables passed and/ or the arguements.

Help is most appreciated -- Thanks -- Scott
C#
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Robocopy : Form
    {
        public Robocopy()
        {
            InitializeComponent();
            
        }
        private void Srcbutton_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
        }
        private void Destbutton_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
        }
        private void Cpybutton_Click(object sender, EventArgs e)
        {
            string SrcFold = folderBrowserDialog1.SelectedPath;
            string DestFold = folderBrowserDialog2.SelectedPath;
            string args = "\"" + SrcFold + "\" " + DestFold + "\" /E /COPY:dat";
            ProcessStartInfo StartInfo = new ProcessStartInfo
            {
                WorkingDirectory = @"C:\RoboCopy_IT_Folder",
                Arguments = "args",
                FileName = @"C:\Windows\System32\robocopy.exe",
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                WindowStyle = ProcessWindowStyle.Normal,
                UseShellExecute = false
            };
            Process NewProcess = new Process();
            NewProcess.StartInfo = StartInfo;
            if (NewProcess.Start())
            {
                NewProcess.WaitForExit();
                //ProcessOutput.Text = NewProcess.StandardOutput.ReadToEnd();                
            }
        }       
    }
}
Posted
Updated 15-May-11 7:01am
v2

1 solution

I think the operand of this line
Arguments = "args";

should not have the double quote characters. You want to send the contents of args to the new process.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900