Using net.exe within VB.net WinForms app to remove a network drive

152 Views Asked by At

I am attempting to add a button to my program that when clicked, will take an IP address of a NAS from a text box and plug it into "net use \\[IP]\IPC$ /delete". my code looks like this:

    Dim netdel As New ProcessStartInfo()
    netdel.FileName = "C:\Windows\System32\net.exe"
    netdel.WorkingDirectory = "C:\Windows\System32"
    netdel.Arguments = "use \\" + Convert.ToString(NAS_IP.Text) + "\IPC$ /delete"
    Process.Start(netdel)

I am not getting any errors or exceptions, but the code simply doesn't work. If I open CMD and type "net use" I still see the IP of the NAS mapped. I have attempted to do this several ways and they all seem to fail. I even had my program write a .bat script on the fly and then execute it, but even that doesn't work. (It is worth nothing that the actual bat script does work when you click on it manually, but launching it from within the code with process.start(netdel.bat) is unsuccessful). Any advice would be greatly appreciated. Thanks in advance!

0

There are 0 best solutions below