C# nbtstat 进程找不到指定的文件

标签 c# process

我正在尝试使用 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";

代码仍然抛出异常。我可以使用其他命令,如 ipconfiggetmacping 等。只是 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/

相关文章:

c - 使用 waitpid 选项等待所有子进程 __WALL

process - 探索 Windows Phone 8 设备的进程/线程?

delphi - TProcessInfo - 获取进程的完整路径

C#多次启动进程

c# - 是否可以将 List<string> 作为事件记录类的属性

c# - 当我的 BackgroundWorker 抛出错误时,如何防止 visual studio 弹出

c# - 无法通过警报调用 javascript 函数

c# - 用于高速和内存高效检测字符串重复的数据结构选择

android - 如何获取已安装应用程序的应用程序标签

c# - 跳过自定义错误页面的身份验证