Good afternoon,
 
This is driving me crazy. I can on my Windows 7 run this installation I've 
created and the custom action successfully writes a database backup-file (a 
.bak-file that it has as an embedded resource in its assembly) to the 
Temp-directory provided by Path.GetTempPath(). On my computer, it restores this 
database successfully, creating the MDF/LDF database-files in the Program 
Files\Manufacturer\Product directory.
 
However, a different user gets access denied to Program Files when the restore 
is attempted. Him being in another country makes this complicated to 
troubleshoot, so I'm wondering if I'm missing some detail in my code here. I am 
running perMachine, and elevated, and set the custom actions to deferred. The 
directory-path sent to the custom action gets sent correctly. The backup-file 
is written correctly to disk by the custom-action. (Please ignore the part of 
the code that writes a .bak-file to disk, it's a remnant.) But the failure 
comes when doing the final step of the "installTpdb"-customaction, which is a 
restore:
 
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"; 
xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension";>
  <Product Id="*" Name="Database WiXTest" Language="1033" Version="4.9.1" 
Manufacturer="MyCompanyName" UpgradeCode="myupgradecoderemoved">
    <Package
      InstallerVersion="200"
      Compressed="yes"
      InstallScope="perMachine"
      InstallPrivileges="elevated"
      Manufacturer="MyCompanyName"
      Platform='x86'  />
    <!-- BEGIN: License Agreement -->
    <WixVariable Id="WixUILicenseRtf" 
Value="SetupResources/LicenseAgreement.rtf" />
    <!-- BEGIN: UI Bitmaps -->
    <WixVariable Id="WixUIBannerBmp" 
Value="SetupResources/WiXDefBannerBitmap.bmp" />
    <WixVariable Id="WixUIDialogBmp" 
Value="SetupResources/WiXDefDialogBitmap.bmp" />
    <!-- BEGIN: Custom Actions -->
    <CustomAction Id='installTpdb' BinaryKey='customPaActions' 
DllEntry='InstallTpdb' Execute='deferred'/>
    <CustomAction Id='tryUpdateTpdb' BinaryKey='customPaActions' 
DllEntry='TryUpdateTpdb' Execute='deferred' />
    <CustomAction Id='tryReadTpdb' BinaryKey='customPaActions' 
DllEntry='TryReadTpdb' Execute='deferred' />
    <CustomAction Id='uninstallTpdb' BinaryKey='customPaActions' 
DllEntry='UninstallTpdb' Execute='deferred' />
    
    <Binary Id='customPaActions' SourceFile='WiX.TPDB.CustomActions.CA.dll' />

    <!-- BEGIN: assign variable for customactiondata -->
    <CustomAction Id="CustomAction1" Property="installTpdb" 
Value="SomeCustomActionDataKey=[INSTALLDIRECTORY]"/>
    <!-- BEGIN: Single MSI -->
    <MediaTemplate EmbedCab="yes" />
    <!-- BEGIN: Application Icon -->
    <Icon Id="appicon.ico" SourceFile="SetupResources/appicon.ico"/>
    <!-- BEGIN: .NET Version Launch Condition -->
    <PropertyRef Id="NETFRAMEWORK45" />
    <Condition Message="You must install Microsoft .NET 4.5">
      <![CDATA[Installed OR NETFRAMEWORK45]]>
    </Condition>
    <!-- BEGIN: File System -->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="TempFolder">
        <Component Id="DatabaseBackupFile">
          <File Id='FileBackupFile' DiskId='1' Source=db-package.bak' 
KeyPath='yes'/>
        </Component>
      </Directory>
      <Directory Id="ProgramFilesFolder">
        <Directory Id="CompanyFolder" Name="MyCompanyName">
          <Directory Id="INSTALLDIRECTORY" Name="Database WiXTest">
          </Directory>
        </Directory>
      </Directory>
    </Directory>
    
    <!-- BEGIN: Features -->
    <Feature Id="ProductFeature" ConfigurableDirectory="TARGETDIR" Level="1">
      <ComponentRef Id="DatabaseBackupFile" />
    </Feature>
    <InstallExecuteSequence>
      <Custom Action="CustomAction1" Before="installTpdb" />
      <Custom Action="installTpdb" Before="tryUpdateTpdb">NOT Installed</Custom>
      <Custom Action="tryUpdateTpdb" Before="tryReadTpdb">NOT Installed</Custom>
      <Custom Action="tryReadTpdb" Before="InstallFinalize">NOT 
Installed</Custom>
      <Custom Action="uninstallTpdb" After="InstallInitialize">(NOT 
UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")</Custom>
    </InstallExecuteSequence>
    <!-- BEGIN: Add/Remove Programs Icon -->
    <Property Id="ARPPRODUCTICON" Value="appicon.ico" />
    <!-- BEGIN: User Interface -->
    <UIRef Id="WixUI_MyUI" />
  </Product>
</Wix>
 
>From the logfile and custom action, it always throws this exception:
 
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the 
target of an invocation. ---> System.UnauthorizedAccessException: Access to the 
path 'C:\Program Files (x86)\MyCompanyName\Database WiXTest' is denied.
 
I think I see the problem in the logfile from the client's machine, and it is:
 
MSI (c) (5C:80) [10:10:58:316]: Machine policy value 'DisablePatch' is 0
MSI (c) (5C:80) [10:10:58:317]: Machine policy value 'AllowLockdownPatch' is 0
MSI (c) (5C:80) [10:10:58:317]: Machine policy value 'DisableMsi' is 0
MSI (c) (5C:80) [10:10:58:317]: Machine policy value 'AlwaysInstallElevated' is 0
MSI (c) (5C:80) [10:10:58:317]: User policy value 'AlwaysInstallElevated' is 0
MSI (c) (5C:80) [10:10:58:317]: Running product '{myproductcoderemoved}' with 
user privileges: It's not assigned.

On my machine, it says:
 
MSI (c) (14:40) [10:58:13:252]: Product installation will be elevated because 
user is admin and product is being installed per-machine.
MSI (c) (14:40) [10:58:13:252]: Running product '{myproductcoderemoved}' with 
elevated privileges: Product is assigned.
 
The question is, what to do about it? Or any way to work around it? Any which 
way to write to Program Files would be awesome. It really is the most 
convenient for me to be able to write to Program Files during the installation. 
The database backup-file contains data, and there will be cases where I need to 
copy a database from a SQL 2005 server to SQL 2008 server on the same machine, 
where backup/restore is the most convenient mechanism. I could achieve all 
things by generating scripts, and generate some scripts for transfering data, 
but I would prefer to do it this way because the database-work utilizes tried 
and tested code that exists in the application associated with the database 
(the application is installed separately.)
 
Thank you in advance for any and every suggestion! :-)
                                          
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to