smallest
Posts: 8
Joined: Mon Jul 14, 2008 2:20 am

Move Files after install

Our app can use optional plug-in DLLs. Traditionally, these were stored in a subfolder of the installation folder (Program Files/OurApp/Plugins). But, we're going to change that to store them in ProgramData/OurApp/Plugins, to get around permissions issues on XP and Vista. So, we want to have the installer automatically copy the old DLLs out of Program Files and into ProgramData, and we want to prompt the user to confirm this action.

It sounds like a job for a "Custom Action", but I'm fairly stumped as to how to make this happen...

Any hints?
vulgrin
Posts: 40
Joined: Fri Jan 11, 2008 9:49 pm

Re: Move Files after install

Yeah, I've been doing a bunch of stuff in this area tonight. You will likely need to create a VBS to do the actual moving of the files. You can pass parameters from the installer into the VBS with code like this:

Code: Select all

pathToFolder = Session.Property("ProgramFilesFolder")
You will need to create the VBS, then in the appropriate "install sequence" (which I'm still very fuzzy about exactly WHERE everything goes - for example, for my uninstall scripts they went under "InstallFinalize" not, Uninstall..) you will need to right click and say "New Attached Custom Action" and pick your VBS file.

On the screen you can specify which function to call, and then the execution conditions at the bottom to decide when to run the code. (For example, code running during uninstall should be tagged with the REMOVE = "ALL" expression.) Then you test, and test, and test some more, and after about 50 iterations of learning how it all works, it will suddenly work for you. You will do a dance of joy, then grab a beer.

(Can you tell how much I love installers? :) No fault to AI - I love this program - but I really hate installers.)

Give it a go and let us know if you have more specific questions as you go along.
vulgrin
Posts: 40
Joined: Fri Jan 11, 2008 9:49 pm

Re: Move Files after install

That code was silly without context - here is an example VBS that I wrote to take out some database files if the user uninstalled SQL Express:

Code: Select all

Function removeDB()
  Dim pathToFolder, root, subfolder, dbpath, logpath, objFS
  Set objFS = CreateObject("Scripting.FileSystemObject")
  pathToFolder = Session.Property("ProgramFilesFolder")
  pathToFolder = pathToFolder + "Microsoft SQL Server"

  if objFS.FolderExists(pathToFolder) then
    set root = objFS.GetFolder(pathToFolder)

    for each subfolder in root.Subfolders

     dbpath = subfolder.Path + "MSSQL/DATA/mydb.mdf"
     logpath = subfolder.Path + "MSSQL/DATA/mydb_log.ldf"
     if objFs.FileExists(dbpath) = True then objFs.DeleteFile dbpath, True
     if objFs.FileExists(logpath) = True then objFs.DeleteFile logpath, True
   Next
end if

End Function

Return to “Common Problems”