我正在尝试使用 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();
不幸的是,该代码抛出异常。
The system cannot find the file specified.
如果 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 窗体和 .NET Framework 4.5。
最佳答案
切换到任何 cpu 或检查操作系统版本并获取环境路径,看看 https://stackoverflow.com/a/21028022/87956
关于C# nbtstat 进程找不到指定的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35224442/