Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
problem in cmd.exe while i open it from c#
..
when i open start > run > cmd
and write this command ..
c:\>msg \server:"192.168.6.5" * "send hello "
the obove command executed correctly
but when i run cmd from c#.net this command get this error

C#
private void button3_Click(object sender, EventArgs e)
        {
            Process.Start("cmd.exe");
      
        }

and then write the same command
c:\>msg \server:"192.168.6.5" * "send hello "
msg is not recognized as an internal or external command...

what's the problem ??
plz help
Posted
Comments
Richard MacCutchan 9-Mar-15 9:54am    
See Solution 1 by phil.o.

You have to provide the full path to the msg.exe executable file.
 
Share this answer
 
Comments
[no name] 8-Mar-15 11:33am    
And why is that neccessary?
phil.o 8-Mar-15 11:46am    
The error message states that there does not exist any preexisting command named msg; that also means that, in all referenced paths for the user, there is no msg.exe, or msg.cmd, or msg.bat, or msg.com, etc., executable. Thus, you have to provide the full executable path in order for it to be launched. That is just pure logic.
[no name] 8-Mar-15 11:51am    
Let me rephrase: Why does it work for him when he launches cmd.exe manually but not via his c# app? Do you assume his c# app runs under some other user account?
phil.o 8-Mar-15 11:54am    
I do not assume anything. I just analyze the error message and deduce that the executable has not been found in any of the directories included in path user variable. It could be, effectively, that the application runs under other credentials than the user's ones; but that's just a guess.
Richard MacCutchan 8-Mar-15 13:32pm    
No it probably means that when he runs it from the command line he is either in the directory where that program resides, or he has it set in his PATH environment variable. Basic command stuff.
Your main mistake is using CMD.EXE. Why, why would you ever need it? You have to start the application or run command which you used to start or run with CMD.EXE, not CMD.EXE itself. It's possible, but it would be totally useless middleman between Process.Start and what you really need to start.

—SA
 
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