0

I have created an installer using WIX toolset. Now I want to copy a file to the user's local system after installation. I have tried all possible ways with CopyFile element but couldn't complete the problem.

I have tried using CopyFile Element but couldn't copy the file.

<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="SAFTRUS_Application" />
        <Directory Id="MyProgramDir" Name="SAFTRUS_Application">
            <Directory Id="CopiedFiles" Name="Copied Files" />
        </Directory>
    </Directory>
</Directory>

<Fragment>
<DirectoryRef Id="MyProgramDir">
    <Component Id="sAFtrUS" Guid="E8A58B7B-F031-4548-9BDD- 
        7A6796C8460D">
        <File Id="FILE_InstallMeTXT" Source="ReadMe.rtf" KeyPath="yes">
            <CopyFile Id="Copy_InstallMeTXT" 
                DestinationDirectory="CopiedFiles" 
                DestinationName="ReadMe1.rtf" />
        </File>
    </Component>
</DirectoryRef>

The file should be copied from installer to end user's system. The File name is ReadMe.rtf, this file is included in my setup project. I want to copy this file to the user's local system where the application is, installed.

So if anyone has a solution, please help me.

Palle Due
  • 5,929
  • 4
  • 17
  • 32
  • 1
    Possible duplicate of [Copy file from setup location to another location in wix on install](https://stackoverflow.com/questions/4363785/copy-file-from-setup-location-to-another-location-in-wix-on-install) – Pavel Anikhouski Jul 11 '19 at 12:44
  • What does this file do? Is it just to show to the user? If so, can you just open it on first application launch? This is an age-old problem with the same answer over and over. Please explain in detail what needs to happen to this file. – Stein Åsmul Jul 11 '19 at 15:19
  • Hi Stein, i want toi copy file to a specific folder in end users system – Sumanth Jul 11 '19 at 15:58
  • I don't fully understand why you don't just install this file with the rest of the files? Do you want to be able to change it without re-compiling the setup? Did you consider putting the content on the web and opening an URL instead? Just trying to narrow things down to understand what the use-case really is. You can even install a default version in case the user is offline. – Stein Åsmul Jul 11 '19 at 21:30
  • HI Stein , i have a text file, so now i want to copy that file to specific folder in end user system after installing the application, so is there any way to do this job . "C:\Windows\System32\drivers" this is the folder where i want to copy that file after installing my application. Now i think you get my point. Please help me out ASAP, this is an urgent requirement for me – Sumanth Jul 15 '19 at 10:43

1 Answers1

0

I used a CustomAction to do this. "copy" is not an executable, but rather a command available within cmd.exe, so you have to run "copy" from within the cmd.exe process

    <CustomAction Id="copy.file" Directory="INSTALLFOLDER"
      ExeCommand="[System64Folder]cmd.exe /c &quot;copy ReadMe.rtf [WindowsFolder]System32\ReadMe.rtf&quot;"
      Return="check" Execute="deferred" Impersonate="no" />

Then reference the action in a Custom element in the InstallExecuteSequence

    <InstallExecuteSequence>
      <Custom Action="copy.file" After="InstallFiles" />
    </InstallExecuteSequence>

I ran into issues copying a file to C:\Windows\System32\drivers if the cmd.exe being used to run the "copy" command was not from the same folder. For instance if [SystemFolder] was used (which is set to C:\Windows\SysWOW64 on 64-bit Windows) above instead of [System64Folder], it wouldn't work. Also didn't give an error either which was odd. From the install log, it looked like copy.file succeeded. Something to be aware of.