have to delete a folder
Hi,
I ve got a vendor MSI and it leaves by uninstall the INSTALLDIR folder. Well, no problem, one custom action and the problem is gone like by hundred other MSIs.
But the problem is, it doesnt work. meanwhile I tried everything... I guess.
As WMI gives me error code 15, eventlogger tells me by VBS Path doesnt exist or Permission denid. The path is correct and the scripts run without problems under my account and with other MSI.
I tried following scripts:
Dim arrFolders()
Dim objWMIService
intSize = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
objWMIService.Security_.ImpersonationLevel = 3
objWMIService.Security_.privileges.addasstring "SeDebugPrivilege", True
strFolderName = "C:\Program Files\pipc\Procbook\"
strFolderName = left(strFolderName, len(strFolderName)-1)
MSGBOX strFolderName
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
GetSubFolders strFolderName
Next
End Sub
For i = Ubound(arrFolders) to 0 Step -1
strFolder = arrFolders(i)
strFolder = Replace(strFolder, "\", "\\")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = '" & strFolder & "'")
For Each objFolder in colFolders
errResults = objFolder.Delete
MSGBOX errResults
Next
Next
-------------------------------------------
dim filesys
dim fso
set fso = CreateObject ("Scripting.FileSystemObject")
if fso.folderexists(Session.Property("CustomActionData")) then
Call fso.DeleteFolder(Session.Property("CustomActionData"),true)
end if
Set fso = Nothing
--------------------------------------------------------------
On Error Resume Next
dim filesys
dim demofolder
dim installdir
dim fso
set fso = CreateObject ("Scripting.FileSystemObject")
demofolder = Session.Property("CustomActionData")
demofolder = left(demofolder, len(demofolder)-1)
if fso.FolderExists(demofolder) then
Call fso.DeleteFolder(demofolder,true)
end if
Set fso = Nothing
All these work (I know that the first is hardcoded ;))
As somebody please any tip, I mean it can be so difficult to delete an empty folder (yes, it is really empty)
Thx
I ve got a vendor MSI and it leaves by uninstall the INSTALLDIR folder. Well, no problem, one custom action and the problem is gone like by hundred other MSIs.
But the problem is, it doesnt work. meanwhile I tried everything... I guess.
As WMI gives me error code 15, eventlogger tells me by VBS Path doesnt exist or Permission denid. The path is correct and the scripts run without problems under my account and with other MSI.
I tried following scripts:
Dim arrFolders()
Dim objWMIService
intSize = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
objWMIService.Security_.ImpersonationLevel = 3
objWMIService.Security_.privileges.addasstring "SeDebugPrivilege", True
strFolderName = "C:\Program Files\pipc\Procbook\"
strFolderName = left(strFolderName, len(strFolderName)-1)
MSGBOX strFolderName
Set colSubfolders = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
For Each objFolder in colSubfolders
GetSubFolders strFolderName
Next
Sub GetSubFolders(strFolderName)
Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")
For Each objFolder2 in colSubfolders2
strFolderName = objFolder2.Name
ReDim Preserve arrFolders(intSize)
arrFolders(intSize) = strFolderName
intSize = intSize + 1
GetSubFolders strFolderName
Next
End Sub
For i = Ubound(arrFolders) to 0 Step -1
strFolder = arrFolders(i)
strFolder = Replace(strFolder, "\", "\\")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name = '" & strFolder & "'")
For Each objFolder in colFolders
errResults = objFolder.Delete
MSGBOX errResults
Next
Next
-------------------------------------------
dim filesys
dim fso
set fso = CreateObject ("Scripting.FileSystemObject")
if fso.folderexists(Session.Property("CustomActionData")) then
Call fso.DeleteFolder(Session.Property("CustomActionData"),true)
end if
Set fso = Nothing
--------------------------------------------------------------
On Error Resume Next
dim filesys
dim demofolder
dim installdir
dim fso
set fso = CreateObject ("Scripting.FileSystemObject")
demofolder = Session.Property("CustomActionData")
demofolder = left(demofolder, len(demofolder)-1)
if fso.FolderExists(demofolder) then
Call fso.DeleteFolder(demofolder,true)
end if
Set fso = Nothing
All these work (I know that the first is hardcoded ;))
As somebody please any tip, I mean it can be so difficult to delete an empty folder (yes, it is really empty)
Thx
0 Comments
[ + ] Show comments
Answers (12)
Please log in to answer
Posted by:
captain_planet
16 years ago
Posted by:
anonymous_9363
16 years ago
Was there some reason why you couldn't use the RemoveFiles table? It's perfectly possible to delete folders using it. http://msdn.microsoft.com/en-us/library/aa371199(VS.85).aspx
Posted by:
aogilmor
16 years ago
Posted by:
mac-duff
16 years ago
Hi,
yes, I cant use the RemoveFile Table because it doesnt work neither. The crazy thing is that at this point of the uninstallation the folder is already emtpy and can be deleteted without problems.
I run, well the system run the vbs in deferred execution in a System Context where I receive this different errors with the different scripts.
Its also the first time that something strange happend to me.
Can u please tell me maybe another solution? JS, BAT (rd /q /s [INSTALLDIR]?
yes, I cant use the RemoveFile Table because it doesnt work neither. The crazy thing is that at this point of the uninstallation the folder is already emtpy and can be deleteted without problems.
I run, well the system run the vbs in deferred execution in a System Context where I receive this different errors with the different scripts.
Its also the first time that something strange happend to me.
Can u please tell me maybe another solution? JS, BAT (rd /q /s [INSTALLDIR]?
Posted by:
anonymous_9363
16 years ago
Posted by:
mac-duff
16 years ago
its possible that something is set wrong, as I told it is a vendor MSI which is totally shitty. I mean I dont know much about MSI but these people know nothing.... It has no structure etc.
But back to the topic, I also checked the sequence and the sequence removefile is called, finally some other files are removed by this. But something seems to block the installdir because at least vbs works in other packages.....
But back to the topic, I also checked the sequence and the sequence removefile is called, finally some other files are removed by this. But something seems to block the installdir because at least vbs works in other packages.....
Posted by:
AngelD
16 years ago
Posted by:
mac-duff
16 years ago
Posted by:
mac-duff
16 years ago
Posted by:
tneubauer
16 years ago
I use the below script using the "call vbscript from embedded code" action and so far it has not failed me. In Wise Package Studio I place it in Execute Deferred under the "Remove Folders" line with the below If-Then statement:
If REMOVE~="ALL" Then
call vbscript from embedded code
End
'========vbscript=====
On Error Resume Next
Dim objFSO, strFolder1
'variable for the folder to delete i.e "c:\program files\Mozilla Firefox"
strFolder1="FolderName"
set objFSO=CreateObject("Scripting.FileSystemObject")
'delete command
objFSO.DeleteFolder(strFolder1) ,True
Set objFSO=Nothing
'======end script======
If REMOVE~="ALL" Then
call vbscript from embedded code
End
'========vbscript=====
On Error Resume Next
Dim objFSO, strFolder1
'variable for the folder to delete i.e "c:\program files\Mozilla Firefox"
strFolder1="FolderName"
set objFSO=CreateObject("Scripting.FileSystemObject")
'delete command
objFSO.DeleteFolder(strFolder1) ,True
Set objFSO=Nothing
'======end script======
Posted by:
sami.msi
16 years ago
Hi Guys,
Want to put light to discussion.
Topic : Have to delete a folder from Vendor Msi
To the above topic there are basically two effective method of resolving the problem
1. Using Script.
2. Using RemoveFile Table
If still does not work mean you dont have to worry at all you can Ignore. if it is a Vendor MSI
If its not an not an Vendor MSI i dont think you would get the problem for deleting folder after Uninstallation.
Want to put light to discussion.
Topic : Have to delete a folder from Vendor Msi
To the above topic there are basically two effective method of resolving the problem
1. Using Script.
2. Using RemoveFile Table
If still does not work mean you dont have to worry at all you can Ignore. if it is a Vendor MSI
If its not an not an Vendor MSI i dont think you would get the problem for deleting folder after Uninstallation.
Posted by:
anonymous_9363
16 years ago
ORIGINAL: sami.msiEh?
If still does not work mean you dont have to worry at all you can Ignore. if it is a Vendor MSI
If its not an not an Vendor MSI i dont think you would get the problem for deleting folder after Uninstallation.
- How do you come to the conclusion that, just because it's a vendor MSI, one can ignore the fact that it doesn't remove file(s) or folder(s)?
- Why do you think one wouldn't come across the problem with one's own MSIs, particularly if it's a locked file problem?
- Why resurrect a thread which is clearly dead?
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.