cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
peterbi
Level 7

Simple (surely) InstallScript (no MSI) question on DeleteFile()

This seems to me a really simple one, but not when I really work on it:(

I try to delete an .ini file from WINDIR at the end of uninstall, it was installed (and modified after installation) by the installer (InstallScript no MSI), but I just can't make it work. Following is the code:

...
TARGETDIR = WINDIR;
sIni = TARGETDIR^"MyFile.ini";
SetFileInfo (sIni, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, "");
if(DeleteFile(sIni) < 0) then
MessageBox ("DeleteFile failed.", SEVERE);

endif;
...


The code is executed, and DeleteFile() returns non-negative value (the SEVERE msg is not displayed), but the file is still there when I navigate to WINDIR.

Any suggestions?


Thanks,
Peter
Labels (1)
0 Kudos
(9) Replies
ChandanOmkar
Level 8

use WindowsFolder in place of WINDIR and then try.....
0 Kudos
RobertDickau
Flexera Alumni

DeleteDir can also return a couple of positive values; perhaps display the specific value? In what event are you calling that code?

(It's probably not necessary to set TARGETDIR to WINDIR, though that doesn't seem it would have a bearing on the issue.)
0 Kudos
peterbi
Level 7

Hi Robert and Chandan,

Thanks you both for your attention to my posts.

First of all, 'WindowsFolder' is not a valid property for InstallScript project (IS2009 help specified "Thsi information does not apply to InstallScript projects".).

Robert is right that it's not necessary to set TARGETDIR here, I directly used WINDIR and got the same result - so he is also right that it is not the problem here.

I changed the code to the following


...
sIni = WINDIR^"MyFile.ini";
SetFileInfo (sIni, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, "");
if(DeleteFile(sIni) != 0) then
MessageBox ("DeleteFile failed.", SEVERE);
...


The code is still executed fine - the failed message is NOT displayed. Any other more robust workaround for DeleteFile() in InstallScript?

I desparately need help now:confused:


Thanks,
Peter
0 Kudos
peterbi
Level 7

Please note the following change:

if(DeleteFile(sIni) != 0) then
0 Kudos
peterbi
Level 7

Hi Robert and Chandan,

Thanks you both for your attention to my posts.

First of all, 'WindowsFolder' is not a valid property for InstallScript project (IS2009 help specified "Thsi information does not apply to InstallScript projects".).

Robert is right that it's not necessary to set TARGETDIR here, I directly used WINDIR and got the same result - so he is also right that it is not the problem here.

I changed the code to the following


...
sIni = WINDIR^"MyFile.ini";
SetFileInfo (sIni, FILE_ATTRIBUTE, FILE_ATTR_NORMAL, "");
if(DeleteFile(sIni) != 0) then
MessageBox ("DeleteFile failed.", SEVERE);
...


The code is still executed fine - the failed message is NOT displayed. Any other more robust workaround for DeleteFile() in InstallScript?

I desparately need help now:confused:


Thanks,
Peter
0 Kudos
peterbi
Level 7

One more thing I forgot (for Robert).

The function was plugged in as OnUninstalled event of the main feature of the product (Setup Design->main_feature->OnUninstalled).

Thanks,
Peter
0 Kudos
peterbi
Level 7

Some updates:

I tried to delete the file during the execution of the code block (added a messagebox before calling DeleteFile()), I could delete it, but after uninstall I found the file was created!

So I think the problem is not DeleteFile() itself, but the sequence (or position at uninstall) to call the function. Obviously some action(s) re-created the .ini file after OnUninstalled event of the main feature. I als tried other features, non of them is late enough to be after the re-creation.

The code is relatively (yes just relatively) simple, I am pasting the main functions in setup.rul below

function OnShowUI()
...
begin
if _IsRestartAndFinish() then
_InitVariablesAfterRestart();
_InitScreen();
_RunUpdatePgm();
...
_RemoveRegistryEntry();
_AllDone();
else
_InitVariables();
_BuildNetworkLists();
_InitScreen();
_DoGUIs();
...
_UpdateFiles();

_UpdateIniFiles();

_RunUpdatePgm();

_AlmostDone();

_AllDone();
endif;

end;

function _DoGUIs()
begin
while (nDoNext <= _DO_UPDATE_FILES)
switch( nDoNext )
case _DO_WELCOME:
_Welcome();
nDoNext = _DO_EULA ;

case _DO_EULA:
_EULA();

case _DO_NUMUSER:
...

case _DO_LOCK_MGR:
...
case _DO_GET_PATH:
...
case _DO_LOCK_FILES:
...
case _DO_UPDATE_FILES:
_DeleteOldFiles();

if ( gIsMultiuser) then
InstallFirstUser();
endif;

nDoNext = _DO_UPDATE_FILES +1;

default:
_Terminate();

endswitch;
endwhile;
end;


At uninstall, 'OnShowUI()' is not executed, and I can't see any other custom code to deal with uninstall, so it seems to me the whole uninstall process is controled by ...\setup.exe -uninst ....

Then which event controller (function call) is late enough that I can use to do the file deletion?


Thanks,
Peter
0 Kudos
peterbi
Level 7

Is that possible to modify the ...\setup.exe -uninst ... to create a log file to what events/functions are executed during uninstall?


Thanks,
Peter
0 Kudos
peterbi
Level 7

All done!

Big lesson to learn for InstallScript projects:(

I got the OnUninstall() function by going to IDE->InstallScript->Advanced->OnUninstall(), and add my function call at the end of OnUninstall(), everything works!


Thanks to anyone who payed attention to my posts.

Regards,
Peter
0 Kudos