Delete an entire subtree using RemoveFile table
Posted 08 January 2002 - 09:21
My product creates an entire (4-level) subtree under INSTALLDIR when the user runs it. I have to remove this during uninstall. I don't know the names of all of the directories that the product creates, because they are user-defined. How can I use RemoveFile table to help me get rid of this tree?
Posted 08 January 2002 - 17:10
The RemoveFile table only seems to work if you know the names of the files you want to remove. If you are using Developer 7.0 there are some InstallScript functions that could help you out like DeleteDir and DeleteFile.
I have been using the following InstallScript for my ISWI 2.03 installs. It removes some registry keys and all files left in the TARGETDIR and CommonFilesFolder. Sorry if it looks hairy.
//-----< FindRemainingFiles >-----------------------------------------
function FindRemainingFiles (hMSI)
STRING sFindDir, sFindFile, sResult, FileList, sPOKey, sSharedDir;
NUMBER RetVal, DirList;
BOOL NoFiles, POE, PORV, POD;
begin
sFindFile = "*.*";
FileList = "";
szMsg = "Finding remaining files in:
" + sFindDir;
SdShowMsg (szMsg, TRUE);
POD = FALSE;
POE = FALSE;
PORV = FALSE;
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
sPOKey = "\\SOFTWARE\\My Company\\PODkey\\3.1";
if RegDBKeyExist (sPOKey) = 1 then
POD = TRUE;
endif;
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
sPOKey = "\\SOFTWARE\\My Company\\POEkey\\3.1";
if RegDBKeyExist (sPOKey) = 1 then
POE = TRUE;
endif;
RegDBSetDefaultRoot (HKEY_CURRENT_USER);
sPOKey = "\\SOFTWARE\\My Company\\PORVkey";
if RegDBKeyExist (sPOKey) = 1 then
PORV = TRUE;
endif;
//Find files remaining in TARGETDIR
FileList = "Files Remaining after uninstall in : " + sFindDir + "
";
sFindDir = TARGETDIR;
RetVal = FindAllFiles (sFindDir, sFindFile, sResult, RESET);
FileList = FileList + sResult + "
";
if RetVal < 0 then
NoFiles = TRUE;
else
NoFiles = FALSE;
while (RetVal = 0)
RetVal = FindAllFiles (sFindDir, sFindFile, sResult, CONTINUE);
if RetVal = 0 then
FileList = FileList + sResult + "
";
endif;
endwhile;
endif;
RetVal = FindAllFiles (sFindDir, sFindFile, sResult, CANCEL);
//if no other POS programs installed then find files remaining in COMMONFILES
if !POE && !PORV && !POD then
FileList = FileList + "
Remaining Shared Files:
";
sSharedDir = COMMONFILES ^ "My Company";
RetVal = FindAllFiles (sSharedDir, sFindFile, sResult, RESET);
FileList = FileList + sResult + "
";
if RetVal < 0 then
NoFiles = TRUE;
else
NoFiles = FALSE;
while (RetVal = 0)
RetVal = FindAllFiles (sSharedDir, sFindFile, sResult, CONTINUE);
if RetVal = 0 then
FileList = FileList + sResult + "
";
endif;
endwhile;
endif;
RetVal = FindAllFiles (sSharedDir, sFindFile, sResult, CANCEL);
//find remaining directories in TARGETDIR
DirList = ListCreate (STRINGLIST);
FindAllDirs (sFindDir, INCLUDE_SUBDIR, DirList);
RetVal = ListCount (DirList);
if RetVal > 0 then
NoFiles = FALSE;
RetVal = 0;
ListSetIndex (DirList, 0);
FileList = FileList + "
Remaining Directories:
";
while (RetVal != 1)
RetVal = ListGetNextString (DirList, sResult);
FileList = FileList + sResult + "
";
endwhile;
endif;
endif;
Delay (1);
SdShowMsg (szMsg, FALSE);
if NoFiles = FALSE then
FileList = FileList + "
These files have not been uninstalled. Do you want to delete them?
";
RetVal = AskYesNo (FileList,NO);
if RetVal = YES then
DeleteDir(sFindDir, ALLCONTENTS);
if !POE && !PORV && !POD then
DeleteDir(sSharedDir, ALLCONTENTS);
endif;
RegDBSetDefaultRoot (HKEY_LOCAL_MACHINE);
if POE then
sPOKey = "\\SOFTWARE\\My Company\\POkey";
else
sPOKey = "\\SOFTWARE\\My Company";
endif;
RegDBDeleteKey (sPOKey);
RegDBSetDefaultRoot (HKEY_CURRENT_USER);
if PORV then
sPOKey = "\\Software\\My Company\\POkey";
else
sPOKey = "\\Software\\My Company";
endif;
RegDBDeleteKey (sPOKey);
endif;
endif;
end;
Posted 09 January 2002 - 16:56