vm.ListDirectoryInGuest() fails using Network Drive Paths

Dec 10, 2010 at 6:22 PM

Have any of you seen this before?

I'm using VS 2010 and recently upgraded my VMware WS from v6.5.4 to v7.1

In my C#, I was previously hard-coding references to a shared folder in a call like this: virtualMachine.ListDirectoryInGuest("\\\\.host\\shared folders\\goober", false, 6000);

  Now in WS 7.x, "\\.host\shared folders" has been replaced with "\\vmware-host\shared folders".   A simple code change to the ListDirectoryInGuest call to use "vmware-host" instead of ".host" makes the code function correctly with WS 7.1.

  However, I decided that it would be cleaner to use a network drive path to let me have the same code work on my WS 6.5.4 installation as well as my WS 7.1 installation.  Enabling the 'Map as a network drive in Windows Guests' option on the Host, drive "Z:" shows up in the guest, mapped to "\\vmware-host\shared folders".   Indeed, in the cmd window of the guest, dir z:\goober shows me the same results as dir "\\vmware-host\shared folders\goober".   However, what I would consider the equivalent change to the ListDirectoryInGuest call does not work. virtualMachine.ListDirectoryInGuest("z:\\goober", false, 6000);  always throws the exception: "Memory allocation failed: out of memory".

  I've tried a few variations on that like using an additional set of \\ after goober, but it didn't help.  Another thing I tried was manually creating another network share "Y" mapped to "\\vmware-host\shared folders".  I tried it because I was concerned that windows explorer was showing the Z share as a 'disconnected network drive', in case that had any bearing.  The manually created Y drive doesn't show as 'disconnected', so I was hopeful...  but in the end the error is the same when it's used in the ListDirectoryInGuest call.

  Any ideas?

Thanks

-bC

Coordinator
Dec 10, 2010 at 9:51 PM

ListDirectoryInGuest is a VMWare function and I can't imagine that it would work with a UNC path (\\server\share). Just use the regular Windows API (System.IO.File, Directory) on those.

VMWareTasks has some history (read this post) on mapping network drives and a convenient class, Vestris.VMWareLib.Tools.Windows.MappedNetworkDrive that encapsulates a mapped network drive with credentials, figures out the remote path based on the VM's IP address and other magic. So you can just use that out of the box. Here's a snippet from a unit test that uses it.

MappedNetworkDriveInfo mappedNetworkDriveInfo = new MappedNetworkDriveInfo();
mappedNetworkDriveInfo.RemotePath = @"C:\";
mappedNetworkDriveInfo.Username = ...
mappedNetworkDriveInfo.Password = ...                
Console.WriteLine("Remote IP: {0}", provider.VirtualMachine.GuestVariables["ip"]);
using (MappedNetworkDrive mappedNetworkDrive = new MappedNetworkDrive(vm, mappedNetworkDriveInfo))
{
 string guestWindowsPath = mappedNetworkDrive.GuestPathToNetworkPath(@"C:\Windows");
 Console.WriteLine("Mapped windows directory: {0}", guestWindowsPath);
 Shell guestShell = new Shell(provider.PoweredVirtualMachine);
 Assert.AreEqual(string.Format(@"\\{0}\C$\Windows", guestShell.IpAddress), guestWindowsPath);
 Console.WriteLine(mappedNetworkDrive.NetworkPath);
 Assert.IsTrue(Directory.Exists(guestWindowsPath));
}

 

May 5, 2011 at 2:57 PM

I currently have a shared folder (via VMware workstation) available from within the guest vm, with a path of "\\.host\shared folders\goober".

I have to do all of that above to simply have that shared path accessible as a drive letter within the guest?

I've noticed that there's a check-box in the GUI dialog of VMware workstation (could be there in other flavors of VMware) for when you add a shared folder, you can elect to have it automatically map to a drive letter in the guest as well.  Is that still only accomplished with the mappednetworkdrive business?

 

Thanks!

Coordinator
May 22, 2011 at 7:07 PM

I am confused, sorry. Shared folders are for the guest to access the host. This whole mapped network drive thing is for the opposite. So which direction are you trying to copy things to?