Search code examples
c#commandpromptcd

I managed to get the command prompt to open, now how do I get it to write lines?


Basically, I want the command prompt to type and execute the command "cd/" by itself. Here's the code I used to open the command prompt: (Windows Form Application Visual c#)

    private void button6_Click(object sender, EventArgs e)
    {
        Process cmd = new Process();
        cmd.StartInfo.FileName = @"C:\Windows\system32\cmd.exe";
        cmd.Start();

    }

Solution

  • Use the Arguments property of the StartInfo property to pass /K (keep windows open) and CD / (change to root)

    private void button6_Click(object sender, EventArgs e)
    {
        Process cmd = new Process();
    
        cmd.StartInfo.FileName = @"cmd.exe";
        cmd.StartInfo.Arguments = @"/K CD /";
        cmd.Start();
    
    }