2014-09-30 2113 views
1

它只是说“'味精'不被识别为内部或外部程序...” 我已经搜索了很多,但还没有找到任何东西。为什么它不认识它?cmd命令msg不起作用

private void button1_Click(object sender, EventArgs e) 
    { 
     string strCmdText;  
     string user = textBox1.Text; 
     string host = textBox2.Text; 
     string time = textBox3.Text; 
     string text = textBox4.Text; 

     if (textBox1.Text == "") 
     { 
      System.Windows.Forms.MessageBox.Show("You haven't specified a user!"); 
     } 
     else if(textBox2.Text == "") 
     { 
      System.Windows.Forms.MessageBox.Show("You haven't specified the host!"); 
     } 
     else if (textBox3.Text == "") 
     { 
      System.Windows.Forms.MessageBox.Show("You haven't specified the shutdown timer"); 
     } 
     else 
     { 
      strCmdText = "/c msg " + user + "/server:" + host + " /time:" + time + " /w " + text; 
      System.Diagnostics.Process.Start("CMD.exe", strCmdText); 
     } 
    } 
+1

'msg'不是程序路径的一部分。 – Ofiris 2014-09-30 12:18:42

+0

味精是一个可执行文件,为什么传递给cmd? – 2014-09-30 12:19:25

+0

msg不算什么.. msg.exe或msg.bat可能是某种东西。 – TGlatzer 2014-09-30 12:20:47

回答

1

我想你有64位机。因此,请尝试指定完整路径为msg.exeC:\Windows\Sysnative\msg.exe

+0

这工作,thx! – Keenjus 2014-09-30 12:43:09

0

请确保“msg”命令在命令行本身(CMD.exe)正常工作。

如果它也提供相同的错误,请确保msg.exe存在于System32文件夹中,并且PATH环境变量具有System32文件夹路径。

follwoing代码似乎很好,但没有奏效。它使“msg.exe”不被识别为内部或外部命令错误。

ProcessStartInfo pi = new ProcessStartInfo();    
pi.FileName = "cmd.exe"; 
pi.Arguments = "/c msg.exe arguments";   
pi.UseShellExecute = false; 
Process.Start(pi); 
Thread.Sleep(5000); 

但设置用户信息到ProcessStartInfo,它的工作,我能够访问位于System32文件夹中的exe。

ProcessStartInfo pi = new ProcessStartInfo();    
pi.FileName = "cmd.exe"; 
pi.Arguments = "/c msg.exe arguments"; 
pi.UserName = "administrator"; 
System.Security.SecureString s = new System.Security.SecureString(); 
s.AppendChar('p'); 
s.AppendChar('a'); 
s.AppendChar('s'); 
s.AppendChar('s'); 
s.AppendChar('w'); 
s.AppendChar('o'); 
s.AppendChar('r'); 
s.AppendChar('d'); 
pi.Password = s; 
pi.UseShellExecute = false; 
Process.Start(pi); 
Thread.Sleep(5000); 

请参阅https://stackoverflow.com/a/10932062/2382414

+0

是的,它在cmd中工作。 – Keenjus 2014-09-30 12:35:06

+0

可以发表评论。 – SSA 2014-09-30 12:36:57