I want to delete files and folders in a CustomAction (and I dont know the names of the files and folder) and I´m trying to write a vbscript for it.
I have gotten the script to work if the folder is located under C:\temp (see example below). But it doesn´t work when trying to delete under C:\Program Files (x86)\...
I think I have path corretly entered, but I can´t see why it doesn´t work so I guess the problem is with the path anyhow.

On Error Resume Next
Dim objFSO
Set WshShell = CreateObject("Wscript.Shell")


path=ProgramFilesx86 & "\avk\RPAVK\*"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder(path), TRUE
objFSO.DeleteFile(path), TRUE

objFSO.DeleteFolder(testpath), TRUE
objFSO.DeleteFile(testpath), TRUE
0 Comments   [ + ] Show Comments


Please log in to comment

Community Chosen Answer

>I had to know that using the MSI table?
Did you read the article I linked to?


Primary key used to identify this particular table entry.
External key the first column of the Component table. This field references the component that controls the file to be removed.
This column contains the localizable name of the file to be removed. If this column is null, then the specified folder will be removed if it is empty. All of the files that match the wildcard will be removed from the specified directory.

The above has my emboldening and underlining. Use '*' as the wildcard
Answered 06/11/2015 by: VBScab
Red Belt

Please log in to comment


- 'path' can't both be a folder and a file;
- the trailing backslash and the asterisk are spurious

Either find a script that recurses through a folder tree performing an action or, better, use the RemoveFile table in the MSI.
Answered 06/11/2015 by: VBScab
Red Belt

  • I don´t get it. It works with "testpath". Why shouldn´t it work with "path" ? Its just a variable with a path saved in it.
Please log in to comment

Any reason why you're not using the MSI table?

path=Chr(34) & ProgramFilesx86 & "\avk\RPAVK" & Chr(34)
Answered 06/11/2015 by: VBScab
Red Belt

  • Thanks! I'll try it out! I don´t know how many files and folders there are under there or their names. If I remember things correctly I had to know that using the MSI table?
  • Still didn´t get it to work. Something wrong with the script. I hade to solve it asap so I just wrote a .cmd-file that I wrapped with the MSI instead. I´ll give it another shot when I have time!
Please log in to comment
Kludge, kludge, kludge...

Using your knowledge of Windows paths and permitted characters, ask yourself "What's the singlemost stand-out difference between 'C:\TEMP' and 'C:\Program Files (x86)'?"

Hint: look up Chr(34)
Answered 06/11/2015 by: VBScab
Red Belt

  • Double quotation. I didn´t get it to work anyway. Maybe I did it wrong then. What should I type?
Please log in to comment
Answer this question or Comment on this question for clarity