net view not creating txt file

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

The following dos command creates a text file of all active computers
in the domain:

net view > c:\test.txt

However the following code does not create the text file. Any idea why
this is? The command executes, but it doesn't create the file.

ProcessStartInfo qOptions = new ProcessStartInfo("net",
"view > c:\\test.txt");

qOptions.UseShellExecute = true;
qOptions.WindowStyle = ProcessWindowStyle.Minimized;
DOS = Process.Start(qOptions);
DOS.WaitForExit();
 
Greg said:
The following dos command creates a text file of all active computers
in the domain:

net view > c:\test.txt

However the following code does not create the text file. Any idea why
this is? The command executes, but it doesn't create the file.

ProcessStartInfo qOptions = new ProcessStartInfo("net",
"view > c:\\test.txt");

qOptions.UseShellExecute = true;
qOptions.WindowStyle = ProcessWindowStyle.Minimized;
DOS = Process.Start(qOptions);
DOS.WaitForExit();

">" is a command shell feature. You could start cmd or command
(depending on OS) with appropriate parameters, but it's probably better
to just start a new thread to write the file yourself from the output.
 
Jon Skeet said:
">" is a command shell feature. You could start cmd or command
(depending on OS) with appropriate parameters, but it's probably better
to just start a new thread to write the file yourself from the output.


What would the parameters be for 'cmd' to accomplish this?
Alternatively, what would the syntax be for the new thread?
 
Greg said:
What would the parameters be for 'cmd' to accomplish this?

Something like

cmd /c net view > c:/test.txt
Alternatively, what would the syntax be for the new thread?

Well, you'd set RedirectStandardOutput to true on the ProcessStartInfo,
then in a new thread, just loop round reading from the
Process.StandardOutput and writing to the file.
 
Jon Skeet said:
">" is a command shell feature. You could start cmd or command
(depending on OS) with appropriate parameters, but it's probably better
to just start a new thread to write the file yourself from the output.

I actually got it using:

cmd /c net view > c:\test.txt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top