cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sriram27
Level 2

DeleteFile fails with 'The system cannot open the file'

In my installer (Basic MSI project) I have a file to be installed under following location - C:\Program Files\Common Files\AppFolder\AppFolder2\17\drivers\test.dll 

I wanted this file to exist only during the installer process.  Post install I want to delete the file.  So I have added a CustomAction to delete the file however I keep getting  "The system cannot open the file". 

My customAction function:

function DeleteDLLFile(hMSI)
STRING szCommonFilesDir, szMBSWVersionDir;
NUMBER nSize,nSize2,nResult;
STRING szFilePath;
begin
// Get the installed path location
MsiGetProperty(hMSI, "TSSCOMMONFILESFOLDER", szCommonFilesDir, nSize);
SprintfMsiLog("In DeleteDLLFile - TSSCOMMONFILESFOLDER - " + szCommonFilesDir);
MsiGetProperty(hMSI, "MBSWVersion", szMBSWVersionDir, nSize2);
SprintfMsiLog("In DeleteDLLFile - MBSWVersion - " + szMBSWVersionDir);
szFilePath = szCommonFilesDir ^ "AppFolder2" ^ szMBSWVersionDir ^ "drivers" ^ "test.dll";

SprintfMsiLog("In DeleteDLLFile - Before path changes '%s'", szFilePath);
// replace backslashes with double backslashes
StrReplace (szFilePath, "\\" , "\\\\", 0);
SprintfMsiLog("In DeleteDLLFile - After path changes '%s'", szFilePath);

SprintfMsiLog("In DeleteDLLFile - Before calling DeleteFile '%s'", szFilePath);
nResult = DeleteFile ("'" + szFilePath + "'");
if (nResult < 0) then
SprintfMsiLog ("Failed to delete '%s' reason '%s'", ERRORFILENAME, FormatMessage(nResult));
else
SprintfMsiLog ("File '%s' was deleted.", szFilePath);
endif;

SprintfMsiLog("In DeleteDLLFile - Finished calling DeleteFile() with file path '%s'", szFilePath);
end;

Installshiled log:

InstallShield 15:03:57: Running InstallScript function f5
InstallShield 15:03:57: Opening stream of file C:\Windows\Installer\MSID294.tmp
InstallShield 15:03:57: Extracting support file IsConfig.ini to C:\Users\~1\AppData\Local\Temp\{E9478B8B-CC39-4AAF-9831-081E21D3C032}\IsConfig.ini
InstallShield 15:03:57: Extracted isconfig.ini to C:\Users\~1\AppData\Local\Temp\{E9478B8B-CC39-4AAF-9831-081E21D3C032}\IsConfig.ini
InstallShield 15:03:57: Got '{DBB5C17E-0AC3-4D0C-9645-D5CBD108697C}' for TempPathGuid from isconfig.ini
InstallShield 15:03:57: Attempting to use temp path 'C:\Users\~1\AppData\Local\Temp\{DBB5C17E-0AC3-4D0C-9645-D5CBD108697C}'
InstallShield 15:03:57: Using new temp path
InstallShield 15:03:57: Cleaning up temp file C:\Users\~1\AppData\Local\Temp\{E9478B8B-CC39-4AAF-9831-081E21D3C032}\IsConfig.ini
InstallShield 15:03:57: Using temp folder C:\Users\~1\AppData\Local\Temp\{DBB5C17E-0AC3-4D0C-9645-D5CBD108697C}
InstallShield 15:03:57: Installing engine...
InstallShield 15:03:57: Using product language 1033
InstallShield 15:03:57: Detected X64 OS
InstallShield 15:03:57: Skipping optional support file _isuser_0x0409.dll
InstallShield 15:03:57: Setting script cmdline...
InstallShield 15:03:57: ProductCode is {9A1E98E9-9819-4F06-8DBB-F5FDC0F8A4EA}
InstallShield 15:03:57: Initializing Engine
InstallShield 15:03:57: Done Initializing...
InstallShield 15:03:57: Registering Msi Server...
InstallShield 15:03:57: Invoking script function DeleteDLLFile
1: In DeleteDLLFile - TSSCOMMONFILESFOLDER - C:\Program Files\Common Files\AppFolder\
1: In DeleteDLLFile - MBSWVersion - 17
1: In DeleteDLLFile - Before path changes 'C:\Program Files\Common Files\AppFolder\AppFolder2\17\drivers\test.dll'
1: In DeleteDLLFile - After path changes 'C:\\Program Files\\Common Files\\AppFolder\\AppFolder2\\17\\drivers\\test.dll'
1: In DeleteDLLFile - Before calling DeleteFile 'C:\\Program Files\\Common Files\\AppFolder\\AppFolder2\\17\\drivers\\test.dll'
1: Failed to delete '' reason 'The system cannot open the file.
'
1: In DeleteDLLFile - Finished calling DeleteFile() with file path 'C:\\Program Files\\Common Files\\AppFolder\\AppFolder2\\17\\drivers\\test.dll'
InstallShield 15:03:57: Returning script function result
InstallShield 15:03:57: CallScriptFunctionFromMsiCA() ends, result 0x0
Action ended 15:03:57: DeleteDLLFile. Return value 1.

 

 

I am new to installshield, please can someone advise on this

 

Labels (1)
0 Kudos
(1) Reply
sriram27
Level 2

Please can someone help with this issue?  I really appreciate all your help!

0 Kudos