How can I delete a Windows Junction using FileSystemObject?

347 views Asked by At

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.

0

There are 0 answers