View Full Version : C# process and net view
Morpheus
11-17-2003, 02:52 PM
I would like to use the net send and net view MS-DOS commands for a project
For the net send, i'm using :
ProcessStartInfo myProcess_startinfo = new System.Diagnostics.ProcessStartInfo("C:\\WINDOWS\\system32\\net.exe","send x.x.x.x Hello World");
This one works fine but the net view command doesn't works and i don't know why :
ProcessStartInfo myProcess_startinfo = new System.Diagnostics.ProcessStartInfo("C:\\WINDOWS\\system32\\net.exe","view >> view.txt");
Any ideas ?
Thanks.
SomeUser
11-10-2004, 03:53 AM
You seem to be right; I found your example didn't work (just as you said). This might be slight overkill, but I've found this to work.
I know this doesn't exactly address why your technique doesn't work, but I hope it solves your problem.
ExecuteAndWait( "net.exe", "view >> view.txt" );
private string ExecuteAndWait( string sFullApplicationPath, string arguments )
{
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5;
string stdout = null;
Process myProcess = new Process();
try
{
myProcess.StartInfo.FileName = sFullApplicationPath;
myProcess.StartInfo.Verb = "Open";
myProcess.StartInfo.Arguments = arguments;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardOutput = true;
myProcess.Start();
stdout = myProcess.StandardOutput.ReadToEnd();
myProcess.WaitForExit();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
throw new Exception( e.Message + ". Check the path: " + myProcess.StartInfo.FileName );
}
else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
throw new Exception( e.Message + ". Access Denied. File " + myProcess.StartInfo.FileName + " could be in use." );
}
}
return stdout;
}
Note: you *could* use the returned string instead of view.txt, if you liked.
Ethraim
01-04-2005, 08:38 PM
check this ste out and see if it's what you whant
http://www.codeproject.com/dotnet/PrataSendMsg.asp
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.