简体   繁体   English

无法使用System.Diagnostic.Process运行nbtstat

[英]Unable to run nbtstat using System.Diagnostic.Process

I have a working piece of code which executes commands using System.Diagnostic.Process. 我有一段代码,使用System.Diagnostic.Process执行命令。 However, when I try to run nbtstat using the same code it does not return anything (neither is there an exception). 但是,当我尝试使用相同的代码运行nbtstat时,它不会返回任何内容(也没有异常)。 When I run hostname (as an example) it returns the hostname. 当我运行主机名(作为示例)时,它返回主机名。

 string result = "";
            //string commandToExec = "hostname";
            string commandToExec = "nbtstat -A 10.10.10.5";
            System.Diagnostics.ProcessStartInfo procStartInfo =
                new System.Diagnostics.ProcessStartInfo("C:\\Windows\\System32\\cmd.exe", "/c " + commandToExec);
            procStartInfo.RedirectStandardOutput = true;
            procStartInfo.UseShellExecute = false;
            procStartInfo.CreateNoWindow = true;
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
            result = proc.StandardOutput.ReadToEnd();

This command 这个命令

nbtstat -A 10.10.10.5

works perfectly well from the command prompt. 从命令提示符完美地运行。 I am not able to understand the problem, neither find resources on the net which could help. 我无法理解这个问题,也无法在网上找到可能有用的资源。 If anyone can guide me in the right direction please? 如果有人能指导我正确的方向吗?

You should call the nbtstat.exe program directly, there is no need to invoke CMD to call it. 你应该直接调用nbtstat.exe程序,不需要调用CMD来调用它。 So use this line instead; 所以请改用这条线;

System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo(@"c:\windows\sysnative\nbtstat.exe", "-A 10.10.10.5");

I also use Sysnative because of Windows64bit redirection. 由于Windows64bit重定向,我也使用Sysnative。 As exaplained in this post 正如这篇文章中提到的那样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Diagnostic.Process中的死锁 - Deadlock in System.Diagnostic.Process 获取密码提示C#System.Diagnostic.Process的通知 - Getting notified of password prompt C# System.Diagnostic.Process 如何抑制使用System.Diagnostic.Process执行的exe的对话框? - How do I supress dialogs from an exe that is executed using System.Diagnostic.Process? 在C#中使用System.Diagnostic.Process及其UninstallString卸载程序 - Uninstall program using System.Diagnostic.Process and its UninstallString in C# 什么是WinRT(C#)上的System.Diagnostic.Process的等价物? - What's the equivalent of the System.Diagnostic.Process on WinRT (C#)? 如何知道是否已System.Diagnostic.Process由于退出超时? - How to know if a System.Diagnostic.Process has exited due to timeout? 我可以捕获用C#的System.Diagnostic.Process()启动的命令行应用程序的APPCRASH吗? - Can I catch APPCRASH of command line app launched with C#'s System.Diagnostic.Process()? 使用System.Diagnostic.Process.Start(“FileName”)启动Kill进程 - Kill process started with System.Diagnostic.Process.Start(“FileName”) 使用System.Diagnostic Process时,我会错过进程开始和捕获输出开始之间的一些输出行吗? - When using System.Diagnostic Process, will I miss some output lines between the start of process and start of capturing output? System.Diagnostic.Process.Start()是否正确运行.exe文件 - Does System.Diagnostic.Process.Start() runs a .exe file correctly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM