22 October 2012

How To Run a "Dos Command" in c# code


Following code is to re - name  the folder user in command in C# code


// Create Command Here
                string commandToExecute = "ren \"New Folder\" \"Deepak Folder\"";

// Create the object of the Process
                System.Diagnostics.Process myProc = new System.Diagnostics.Process();
                myProc.StartInfo.UseShellExecute = false;
                myProc.StartInfo.RedirectStandardOutput = true;

// set the cmd.exe  file name of the Process
                myProc.StartInfo.FileName = "cmd.exe";

// set the command to execute   !! remember "/c" is must
                myProc.StartInfo.Arguments = "/c "+ commandToExecute;
                commandToExecute;
                myProc.Start();

No comments:

Post a Comment