1

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

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank You Liren, Its working with a Windows service that just can't seem to display a message when i start the Service service
@KizitoSteven Under normal circumstances, Windows services cannot interact with the desktop, which includes the cmd prompt. There are steps to let it, but it's better to out put the messages to a log file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.