我正在尝试使用nbtstat
获取我们客户端的MAC地址。我正在使用System.Diagnostics.Process
来执行该命令。
Process p = new Process();
p.StartInfo.FileName = "nbtstat";
p.StartInfo.Arguments = string.Format("-a {0}", principal.Name);
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
很遗憾,那段代码给了我一个异常。
系统找不到指定的文件。
如果nbtstat的exe文件在System32文件夹中,我认为它应该可以在没有完整路径的情况下工作。但是无论如何,我还是尝试使用了完整路径。
p.StartInfo.FileName = @"C:\Windows\System32\nbtstat.exe";
这段代码仍然抛出异常。我能够使用其他命令,比如ipconfig
、getmac
、ping
等等,只有nbtstat
会导致问题。我已经仔细检查了nbtstat.exe
的目录,它在正确的文件夹中。我也尝试使用ProcessStartInfo
,像这样:
ProcessStartInfo info = new ProcessStartInfo();
// set properties like above
Process.Start(info);
此外,这也无法帮助(如果这个方法能正常工作但上面的代码不能,会让我感到困惑,因为它们应该完全一样,对吗?)。
我正在使用Windows Forms和.NET Framework 4.5。