sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

An issue removing the installation folder

Hello, thanks for considering my question.

I am facing an issue when the installation folder is not removed and there is no prompt to reboot to ensure the folder is removed after a reboot.

The steps are like this:
1. Install the product
2. Open command prompt and cd to the product's installation folder (program files\product_name)
3. Run silent uninstall
4. Uninstallation completes successfully, all files and features are removed, but the installation folder remains.

When performing a non-silent uninstall from the installation folder (invoking msiexec manually with the /i parameter), the same issue is present. Folder is not removed and no prompt to reboot.

It is obvious why the installation folder wasn't removed, and the MSI log file contains an entry stating the failure.
My question is what I can do to prompt to reboot and ensure the folder will be removed upon the reboot.
I thought this was a built-in MSI functionality, but that doesn't seem to be the case.

Thanks in advance (installer!)
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

To work around this issue, I've implemented a custom action that calls the MoveFileEx API, but somehow it doesn't work - no registry entry is created for the folder to be deleted upon a reboot.

The custom action is invoked as `deferred`, under local system account.
Last edited by sasha on Mon Oct 23, 2023 8:58 pm, edited 1 time in total.
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

It appears there is a bit of deficiency in the AI method of calling APIs in DLLs. At least I don't see a clean way to pass a null pointer that the MoveFileEx requires.
I've emulated it by passing two integers of value zero (for the middle parameter of the API).
I also tried the `UnicodeString` with the immediate value of zero.
The result is the same - no registry value to delete the folder is created. Here is from the log file:

MSI (s) (50:C8) [12:38:22:433]: PROPERTY CHANGE: Adding RemoveInstallFolder property. Its value is 'C:\Windows\system32\Kernel32.dll?B;PROPERTY;C;MoveFileExW;B;S;I;c:\tmp?B;S;I;0?V;I;I;4?'.

Action ended 12:38:22: AI_DATA_SETTER_4. Return value 1.
MSI (s) (50:C8) [12:38:22:433]: Doing action: RemoveInstallFolder
Action start 12:38:22: RemoveInstallFolder.
Action ended 12:38:22: RemoveInstallFolder. Return value 1.
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

Here's some more data. With this setup the registry entry is created, but it's contents are very surprising.
PROPERTY CHANGE: Adding RemoveInstallFolder property. Its value is 'C:\Windows\system32\Kernel32.dll?B;PROPERTY;C;MoveFileExW;Q;S;I;c:\tmp1?B;S;I;0?V;I;I;4?'

Basically, the parameters say 'remove the folder named c:\tmp1'. The first parameter is the unicode string passed by reference, second is unicode string passed by reference with the immediate value of zero, the third parameter is integer with the immediate value of 4 (delete on reboot).

Here is what gets written to the registry:
\??\c:\tmp1
\??\C:\Windows\system32\0

That's completely unexpected.
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

OK, looks like things are much better with this set of parameters:
Adding RemoveInstallFolder property. Its value is 'C:\Windows\system32\Kernel32.dll?B;PROPERTY;C;MoveFileExW;B;S;I;c:\tmp?V;I;I;0?V;I;I;4?'.

Passing integer (zero) by value for the nullptr parameter results in the correct registry entry created.

Now, the problem is when the APPDATA property is used in the place of the first parameter. No registry entry is created.
Adding RemoveInstallFolder property. Its value is 'C:\Windows\system32\Kernel32.dll?B;PROPERTY;C;MoveFileExW;B;S;P;APPDIR?V;I;I;0?V;I;I;4?'.

I suspect that's because the action is deferred (or at the commit). Which means the properties are not available.
As it appears the MoveFileEx API requires elevation, I'm not sure how to work around that.
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

Well, it appears the only option is to write some script.
Unless somebody can tell me how to force AI to mark a folder for deletion.
sasha
Posts: 25
Joined: Fri Oct 20, 2023 8:37 pm

Re: An issue removing the installation folder

Here is the script in case it helps someone:

Code: Select all

#this script is used to solve the issue of removing the installation folder when it is locked while uninstalling 
# (like uninstalling while in the command prompt in the install folder)

$installPath = $args[0]

$MethodDefinition = @'
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, int dwFlags);
'@

$Kernel32 = Add-Type -MemberDefinition $MethodDefinition -Name "Kernel32" -Namespace "Win32" -PassThru

$Kernel32::MoveFileEx($installPath, [NullString]::Value, 4) 
Catalin
Posts: 6608
Joined: Wed Jun 13, 2018 7:49 am

Re: An issue removing the installation folder

Hello and welcome to our forums,

First of all, congratulations on finding a solution and thank you very much for sharing it with us!

I am sure this will be of help for further users facing a similar scenario.

Now, the reason why the folders are not removed on uninstall is because the folder is kept in use by the command prompt.

However, it looks like the WIndows Installer does not detect this correctly and therefore does not prompt the "FileInUseDialog", resulting in no reboot being done.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”