Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I'm tring to code a program that returns netstat output.

I put a PsExec.exe on the other machine.
There are no perrmission issues.

Process netStat = new Process();
netStat.StartInfo.UseShellExecute = false;
netStat.StartInfo.CreateNoWindow = true;
netStat.StartInfo.FileName = @"cmd.exe";
netStat.StartInfo.Arguments = @"\\10.190.167.200\r10\SilentInstall\Tools\PsExec.exe netstat";
netStat.StartInfo.RedirectStandardOutput = true;
netStat.Start();
string output = netStat.StandardOutput.ReadToEnd();


even that i see the command run the netstat, the output returns ""

Any ideas?
Thanks, Imbaro
Posted
Updated 18-Dec-13 5:26am
v2

1 solution

Prefix your argument line with "/C " what indicates: Run Command and then terminate.

And of course comment out my test line with: "c:/ dir" and uncomment yours.

         Process netStat = new Process();
         netStat.StartInfo.UseShellExecute = false;
         netStat.StartInfo.CreateNoWindow = true;
         netStat.StartInfo.FileName = @"cmd.exe";
//         netStat.StartInfo.Arguments = @"C/ \\10.190.167.200\r10\SilentInstall\Tools\PsExec.exe netstat";
         netStat.StartInfo.Arguments = @"/C dir";
         netStat.StartInfo.RedirectStandardOutput = true;
         netStat.Start();
         string output = netStat.StandardOutput.ReadToEnd();
 
Share this answer
 
Comments
imbaro 19-Dec-13 2:00am    
Hi, It still returns "".
The change is that the cmd screen apears for much shorter time(I see it returns output)
I did "/C" and not "C/"

Thanks,
Iimbaro.
Adam Zgagacz 19-Dec-13 9:36am    
This is strange. I've tested your code with "dir" command not with "PsExec.exe" so it's not the same.

Did you try to run from command line:
\\10.190.167.200\r10\SilentInstall\Tools\PsExec.exe netstat

did it produce any output?

Also you can try from Windows start/run:
cmd /K "\\10.190.167.200\r10\SilentInstall\Tools\PsExec.exe netstat"

/K option will keep command line window open. Do you see any result when running this way?


imbaro 19-Dec-13 10:47am    
I tried to run without the IP.
netStat.StartInfo.Arguments = @"/C netstat -a -p TCP";
and the arguments returned great.
With /K the proccess stuck on "netStat.StandardOutput.ReadToEnd()"
Adam Zgagacz 19-Dec-13 11:16am    
I was advising to run /K option from Windows Start/Run (just as a part of testing):

cmd /K "\\10.190.167.200\r10\SilentInstall\Tools\PsExec.exe netstat"

When run programatically will stuck becuase CMD window will not close. But when you run it manually maybe you can figure it out what's happening.
Adam Zgagacz 19-Dec-13 11:21am    
One more thougt:
In case you didnt see it, check it out:
http://ss64.com/nt/psexec.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900