Kizito Steven
Kizito Steven

Reputation: 17

Using running CMD commands in C#

I have a program that I want to send cmd msg, initially sending a msg from CMD is msg * Hello Worlld, I have tried it the same way in C# but I have failed to get it right.

Process WindowsProcess = new Process();
ProcessStartInfo PSI = new ProcessStartInfo();

private void WindowsNotifier(string msg)
{
    PSI.FileName = "cmd.exe";
    PSI.Arguments = "/c msg * '"+msg+"'";
    WindowsProcess.StartInfo = PSI;
    WindowsProcess.Start();
}

Thank You

Upvotes: 1

Views: 91

Answers (1)

Liren Yeo
Liren Yeo

Reputation: 3451

I suppose you can simply do this:

private void WindowsNotifier(string msg)
{
    Process.Start("cmd", @"/c msg * " + msg);
}

/c to close the cmd prompt or /k to keep it open. I am assuming you are trying to do msg * TEXT_HERE in cmd prompt.

Alternatively, you can type your commands in a text file, save it as .bat batch file. Then simply run:

System.Diagnostics.Process.Start(batchFilePath);

Upvotes: 1

Related Questions