InstallShield利用环境变量得到INSTALLDIR,结合custom action来实现完全卸载

InstallShield 2012 LE版本中,

1. 自己定义了一个环境变量,叫做mypath,

2. 在custom action中,添加一个action,使用下面的代码来删除子文件夹和文件。

removeNew

Function removeNew()

	Set WshShell = CreateObject("WScript.Shell")
	Dim strFolder, intAnswer
	strFolder =  WshShell.ExpandEnvironmentStrings("%mypath%")
	strFolder = Left(strFolder, Len(strFolder) - 1)
	
	'strFolder = "C:\NewTemp"
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFolders = objFSO.GetFolder(strFolder)
	
	MsgBox "The folder " & fldr & " exists so now to delete all folders inside.", vbInformation
	
	intAnswer = Msgbox("Delete all CATS folder and files?", vbYesNo, "Delete Files")
	If intAnswer = vbNo Then
		Exit Function
	End If
	
	recurse objFolders
	
	'delete the folder itself
	If objFSO.FolderExists(strFolder) Then
		objFSO.DeleteFolder(strFolder)
	End If
	
	Set objFSO = Nothing
	Set objFolders = Nothing
	Set WshShell = Nothing
	
End Function


sub recurse(byref objFolders)
	dim subfolders,files,folder,file
	set subfolders = objFolders.subfolders
	set files = objFolders.files
	for each file in files
		on error resume next
		name = file.name
		file.Delete True
	   If Err Then
		 MsgBox "Error deleting:" & Name & " - " & Err.Description, vbInformation
	   Else
		 MsgBox "Deleted:" & Name, vbInformation
	   End If
	   On Error GoTo 0
	next  
	for each folder in subfolders
		recurse folder
		If UBound(Split (folder.path, "\")) > 0 Then
		    name = folder.name
			folder.Delete True
			If Err Then
				MsgBox "Error deleting:" & Name & " - " & Err.Description, vbInformation
			Else
				MsgBox "Deleted:" & Name, vbInformation
			End If
			On Error GoTo 0
		End If 
	next   
	set subfolders = nothing
	set files = nothing
end Sub



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值