Network drive map: "net.exe USE" vs WshNetwork.MapNetworkDrive?

I am looking for a map in my program. My users can use every version of Windows with XP. Therefore, I need the most universal method. I used the first method before and, as a rule, it worked well for me. But there really is no way to catch bugs with it (which I know anyway). The second one will easily allow me to wrap a try / catch block around it, but for all the searches that I performed for alternatives to method 1, I only skipped method 2 once. Therefore, I have to wonder if this is enough for such a diverse environment. Can someone tell me if method 2 is safe for most circumstances?

Method 1

Process.Start("net.exe", @"USE Z: \\server\share /user:domain\username password").WaitForExit(); 

Method 2, referencing the Windows Script Host object model

 IWshNetwork_Class network = new IWshNetwork_Class(); network.MapNetworkDrive("k:", @"\\server\share"); 
+6
source share
1 answer

Another approach would be to infer the actual Win32 apis (WNetAddConnection2A, WNetCancelConnection2A, etc.). Check out http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.php/c12357/

+4
source

Source: https://habr.com/ru/post/911162/


All Articles