1

I need to delete a sqlite database file folder. I have written a custom action to delete this folder after InstallFinalize. If I run my MSI from command prompt with administrator privilege, it is deleting that folder. Otherwise the sqlite database folder is not removed.

I have added the property tag in Product.wxs file,

 <Property Id="MSIUSEREALADMINDETECTION" Value="1" />

I have added InstallPrivileges="elevated" also.Nothing worked for me. The windows user I logged in has administrator privilege. Delete folder works if the msi is run as administrator via command prompt. I need to open the installer as administrator.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2725407
  • 400
  • 1
  • 4
  • 16
  • If I recall correctly, even if the MSI is being installed with admin privileges, your custom action isn't being run with them by default. You need to set `Impersonate="yes"` on the `CustomAction` element, I believe. – Cameron Nov 24 '14 at 14:44
  • 1
    Right click `msi`, `Run as administrator`. Also check [this](http://stackoverflow.com/a/24486554/1997232) and [this](http://stackoverflow.com/q/14348156/1997232). Is UAC enabled? – Sinatr Nov 24 '14 at 14:44
  • Ignore my last comment, I seem to have misread your question :P – Cameron Nov 24 '14 at 14:51
  • @Sinatr Right click msi, Run as administrator deleting the sqllite folder.UAC is already enabled. – user2725407 Nov 24 '14 at 15:19
  • Do you have the InstallScope="perMachine"? – Joe Nov 24 '14 at 18:05
  • 2
    MSIUSEREALADMINDETECTION is not relevant here. You will not be elevated after InstallFinalize unless you run as administrator, that's the way Windows Installer works. If you run the CA with impersonation=yes it will not be elevated unless you run the MSI elevated. You will be elevated only before InstallFinalize (and after InstallInitialize) and if you are deferred and run with no impersonation. Unfortunately you may then find that the elevated custom action running with the system account cannot access the db, in which case you are stuck doing what you are currently doing. – PhilDW Nov 24 '14 at 21:06

1 Answers1

2

I came across this, and it is possible to run your installer as admin using a custom action which you set to be called at the beginning of your installer. Here is a post I found which explains the solution.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Damien Doumer
  • 1,991
  • 1
  • 18
  • 33
  • In the post, it also mentions that we should avoid using this because: "against best practices and it may result in fallout which won't be supported." Do you know what is the downside when using this approach? – Le Ngoc Thuong May 12 '23 at 01:03