1

I'm mounting a VHD to a folder (junction) using diskpart.

After unmounting the VHD, I need to delete the folder using FileSystemObject.

 var vhdPath = "D:\SomeVhd.vhd";   
 var fsObj = new ActiveXObject("Scripting.FileSystemObject");
 var TypeLib = WScript.CreateObject("Scriptlet.TypeLib");
 var vhdmountpoint = fsObj.GetDriveName(vhdPath) + "\\" + TypeLib.Guid;

 //Mount with diskpart here, vhdmountpoint is now a junction
 //Dismount with diskpart here, vhdmountpoint still a junction

 if (fsObj.FolderExists(vhdmountpoint)) { //returns true!
     fsObj.DeleteFolder(vhdmountpoint); //Returns path not found
  }

Am I missing something?

P.S.

I got around this issue by doing:

 var shell = WScript.CreateObject("WScript.Shell");
 shell.Run("cmd /c rmdir " + vhdmountpoint);

I suppose that counts as a hack.

Bernardo Rivas
  • 109
  • 1
  • 8
  • FSO is simplistic, use the answers in the [superuser question](http://superuser.com/questions/285581/how-to-delete-a-junction-by-using-command-line-in-windows-7) – Hans Passant Dec 20 '14 at 03:00
  • Another possible option is to see if you can use the [Dismount](http://msdn.microsoft.com/en-us/library/aa390368%28v=vs.85%29.aspx) method on the [Volume object](http://msdn.microsoft.com/en-us/library/aa394515%28v=vs.85%29.aspx) obtained using WMI. – slugster Dec 21 '14 at 00:39

0 Answers0