Question Why is "net use" being so strange?


New member
May 4, 2017
Programming Experience
Hey, I'm trying to use a "net use" command that I use to disconnect from all network paths, but when I use it in C# it doesn't do anything. And when I try to run "net use" separately and not pass all the other arguments I noticed that it returns text as if I had no network paths, but when I run the exact same command in CMD it return a list of my network paths.

Here's part of the code:
Resetproc.StartInfo.UseShellExecute = false;Resetproc.StartInfo.RedirectStandardOutput = true;
Resetproc.StartInfo.FileName = "net.exe";
Resetproc.StartInfo.Arguments = "use";
//Resetproc.StartInfo.Arguments = "use * /delete /yes";

String resetOutput = Resetproc.StandardOutput.ReadToEnd();
Log.AppendText(resetOutput + "\r\n----------\r\n");

This code includes the part where I send the output to a textbox I've named "Log".

Resetproc is a process element I put into my windows form.

The commented line is the command that I want to use, but I commented it out so I could try net use.

Here's a pic of the output (white is C#, black is CMD):

Thank you,
Last edited:
Even better would be if someone could tell me an alternative I could use. I want to remove all connections to shared resources like with that net use command, and I also want to connect to my works archive through \\**-***-**\username.
ok I have no idea why that xcode thing didn't work

Apparently the option is case-sensitive and must be lower-case. I have edited your post accordingly.

Do people usually not use these types of functions or something?

Are you certain that the NET command is executing in a security contezxt that includes all the drives your security context has mapped? Is it executing as you? Is it executing with the necessary admin privileges to disconnect the shares? etc..

Typically when you execute command X in a cmd line and it returns different results to executing it in a c# program, it's because it's executing as a different user, or with different permissions

here's an old blog post from a codeguru user who wrote a helper library to wrap the windows api commands for mapping and unmapping drives:
Looks like just adding his class file to your project and using it will be sufficient to obviate use of command line programs entirely
Last edited:
Top Bottom