Just use Process.Start
System.Diagnostics.Process.Start("CMD.exe","/c net use * /delete");
If you insist on a managed code approach (why?) you can do something like:
foreach(var letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
{
try {
network.RemoveNetworkDrive(letter + ":");
} catch {}
}
or better yet (depending on how flexible you are with the required behviour), iterate on this instead:
// assumes using System.IO
var networkDrives = DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Network))
foreach(var networkDrive in networkDrives)
I'd still opt for just using Process.Start
as being far cleaner and more reliable. Once you start down the road of re-implementing 'trivial' functionality you often quickly find out how non-trivial it really is.
Further on why your question itself might need reconsidering - why would you insist on removing all network drive mappings anyway? If you are mapping Z: for example, you know what drive needs to be unmapped. You can have something like this:
public void MapDrive(char driveLetter, string networkPath, string userName, string password)
{
try { network.RemoveNetworkDrive(driveLetter + ":"); } catch {}
network.MapNetworkDrive(driveLetter + ":", @shared_path, Type.Missing, username, password);
}
because surely if you're creating the drive mappings you inherently know which drive letters need to be free as opposed to blowing all network drive mappings away.