I'm looking to map a drive in my program. My users can be using every version of Windows from XP on up. So I need the most versatile method. I have used the first method before and generally it's worked well for me. But there really isn't way to catch errors with it (that I know of anyway). The second will easily let me wrap a try/catch block around it, but for all the searching I've done for an alternatives to method 1, I've only run across method 2 once. So that leaves me to wonder if its reliable enough for such a varied environment. Can anyone 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");
The other approach would be to pinvoke the actual Win32 apis (WNetAddConnection2A, WNetCancelConnection2A, etc). Check out http://www.codeguru.com/csharp/csharp/cs_network/windowsservices/article.php/c12357/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With