0

I am using VBscript to delete folder recursively. The folders present are SERVIGISTICS\EDSSolo5.8\"Several more folders and batch files"....

I am using

If oFSO.FolderExists("C:\Program Files\SERVIGISTICS")then
   oFSO.DeleteFolder "C:\Program Files\SERVIGISTICS", True
End if

The oFSO.DeleteFolder pops out runtime error "Permission Denied" I am running the script in System Context which has full permissions to that directory. Administrator is the owner of the folder

Idan
  • 5,405
  • 7
  • 35
  • 52
  • This might happen if some program still has an open handle to that folder or something in it. Use [Process Explorer](https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer) or [`handle`](https://learn.microsoft.com/en-us/sysinternals/downloads/handle) to verify. – Ansgar Wiechers May 21 '18 at 07:41
  • Have you tried to delete the folder manually at the same time? – omegastripes May 21 '18 at 08:25
  • @omegastripes Yes, manually it is deleting without any problem – Chitrarth Sahai May 22 '18 at 05:14
  • Try to use CMD: `Path = "C:\Program Files\SERVIGISTICS": MsgBox "Return code: " & CreateObject("WSCript.Shell").Run("cmd.exe /c rmdir /s /q """ & Path & """", 0, True)`, or even WMI. – omegastripes May 22 '18 at 07:43
  • Thanks a lot...It worked like a charm – Chitrarth Sahai Jun 27 '18 at 10:27
  • omegastripes' code works provided all VBA references to the folder are released first. That is, you might need to add `ChDir ([some other folder path])` first to make it work, otherwise you might still get the permission denied error. – Miqi180 Nov 09 '21 at 04:20

0 Answers0