Question Why is "net use" being so strange?

Exouxas

New member
Joined
May 4, 2017
Messages
4
Programming Experience
5-10
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";
Resetproc.Start();

String resetOutput = Resetproc.StandardOutput.ReadToEnd();
Resetproc.WaitForExit();
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): https://i.gyazo.com/2d3882a3996e8f9576529a1b21cac041.png


Thank you,
Exouxas
 
Last edited:

Exouxas

New member
Joined
May 4, 2017
Messages
4
Programming Experience
5-10
ok I have no idea why that xcode thing didn't work
 

Exouxas

New member
Joined
May 4, 2017
Messages
4
Programming Experience
5-10
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.
 

Exouxas

New member
Joined
May 4, 2017
Messages
4
Programming Experience
5-10
Bump.

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

cjard

Member
Joined
Jan 25, 2012
Messages
5
Programming Experience
10+
Bump.

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: http://www.codeguru.com/csharp/csha...rticle.php/c12357/C-Map-Network-Drive-API.htm
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