NET VIEW behaves differently when used with Process.Start ()

I use net.exein my program to view all the computers in the workgroup.

The code is as follows:

   var net = new Process();

   net.StartInfo.FileName = "net.exe";
   net.StartInfo.CreateNoWindow = true;
   net.StartInfo.Arguments = @"VIEW /DOMAIN:my-workgroup";
   net.StartInfo.RedirectStandardOutput = true;
   net.StartInfo.UseShellExecute = false;
   net.StartInfo.RedirectStandardError = true;
   net.Start();

The command works great when executed in the shell, but when I use the code shown, the command returns the device is not connected.

I also tried to run the program as an administrator, and that doesn't make any difference.

The domain name indicated is actually a workgroup .

For net.exeworks in a shell, indicating that the workgroup is working fine.

, , net view . , Process.Start() - .

- Process.Start()?

+3
1

, , , ;

,

class Program
{
    static void Main(string[] args)
    {
        var net = new Process()
        {
            StartInfo = new ProcessStartInfo("net.exe", @"view /domain:domain")
            {
                RedirectStandardOutput =  true,
                UseShellExecute = false,
            },


        };
        net.OutputDataReceived += WriteToConsole;
        net.ErrorDataReceived += WriteToConsole;
        net.Start();
        net.BeginOutputReadLine();

        net.WaitForExit();
        Console.ReadLine();
    }

    private static void WriteToConsole(object sender, DataReceivedEventArgs e)
    {
        Console.WriteLine(e.Data);
    }
}
0

All Articles