Writing custom action scripts
For basic custom action scripts, you can use any supported scripting language like VBScript or JScript. For the BPSDK sample installer, VBScript was used.
When using Visual Studio .NET to create a basic setup project, it’s important to know that custom action scripts run in deferred mode. This means that many of the installer session properties provided by the Windows Installer service won’t be available when the custom action script is run. Keep this limitation in mind as you write the custom action scripts for your integration.
The custom action scripts for Business Portal integrations need to perform some basic functions:
Finding the installed files The custom action script must know where the files installed by the installer have been placed. One way to do this with a script that runs in deferred mode is to use the CustomActionData property of the custom action script. When the installer is run, it can set the value of the CustomActionData property, which can be retrieved in the script using the following code:
InstallLoc = Session.Property("CustomActionData")
Finding the Business Portal installation The location of the Business Portal installation can be found by using the Installer object from the Windows Installer service to look up information about installed products. Since the Business Portal was installed using the Windows Installer service, it is included in the list of installed products. For Great Plains, you will search for the product named “Microsoft Business Portal for Great Plains”. For Solomon, you will search for the product named “Microsoft Business Portal for Solomon”. An example of this is found in Example custom action scripts.
Finding the Business Portal \bin folder The location of the \bin folder for the Business Portal will depend on the web site selected in the installation. The location is written to the Windows Registry during the Business Portal installation, so the value can be retrieved by the custom action script. An example of this is found in Example custom action scripts.
Copying and deleting files and folders Standard VBScript commands for the Windows Scripting Host are used to copy and delete files when adding or removing them from the Business Portal installation. Documentation for the Windows Scripting Host is available online from msdn.microsoft.com.
Invoking the MBF Packager The Run command is used to invoke other applications such as the MBF Packager from within the custom action script. Command line options control the actions of the MBF Packager. Refer to Installing package files for more information about running the MBF Packager from a command line.
Example custom action scripts
The following is the Install custom action script used for the Great Plains version of the BPSDK sample installer. The custom action is written in VBScript.
'This script runs after all files have been copied onto the system. 'It also runs when the installation is repaired. Set sh = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") 'Connect to Windows Installer object Dim installer : Set installer = Nothing Set installer = CreateObject("WindowsInstaller.Installer") 'Look up information for the Business Portal ProductName = "Microsoft Business Portal for Great Plains" For Each productCode In installer.Products If LCase(installer.ProductInfo(productCode, "ProductName")) _ = LCase(ProductName) Then Exit For Next If IsEmpty(productCode) Then MsgBox "Business Portal is not installed." Quit End If 'Look up the install location for the Business Portal BPLocation = installer.ProductInfo(productCode, "InstallLocation") 'Set up the locations that specify where to place things 'bin folder, as determined by the Registry key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Business Framework\" _ & "Install\BinInstallDir" BPBin = Sh.RegRead(key) 'map folder BPMap = BPBin + "map\" 'application folder BPApp = BPLocation + "Applications\" 'Find out where the various pieces were installed by looking 'at the CustomActionData property passed from the installer If(IsEmpty(Session)) Then 'Not running from within the installer. Get the source path based 'on the current folder. InstallLoc = sh.CurrentDirectory InstallLoc = Left(InstallLoc, InStr(InstallLoc, "\Scripts")) Else 'Running inside the installer, so use the CustomActionData InstallLoc = Session.Property("CustomActionData") End If '-------------------------------------------------------- 'Note that other Session properties aren't available 'since this custom action is running in a deferred state '-------------------------------------------------------- 'Copy the items to the appropriate Business Portal locations 'Business Components fso.CopyFile InstallLoc & "Bin\*", BPBin, true 'Entity Maps fso.CopyFile InstallLoc & "Map\*", BPMap, true 'Association Assemblies fso.CopyFile InstallLoc & "Associations\*", BPBin, true 'Application folder content fso.CopyFolder InstallLoc & "Application\*", BPApp, true 'Run the MBF Packager to install the package files sh.Run Chr(34) & BPBin & "MbfPackager.exe" & Chr(34) & " " _ & "Import /P:" & Chr(34) & InstallLoc & "PackagerData/BPSDKInstall.project" _ & Chr(34) & " /I:Keep", 0, True
The following is the Uninstall custom action script used for the Great Plains version of the BPSDK sample installer. The custom action is written in VBScript.
'This script runs before any files are actually removed from system Dim fso, f, f1, fc On Error Resume Next Set sh = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") 'Connect to Windows Installer object Dim installer : Set installer = Nothing Set installer = CreateObject("WindowsInstaller.Installer") 'Look up information for the Business Portal ProductName = "Microsoft Business Portal for Great Plains" For Each productCode In installer.Products If LCase(installer.ProductInfo(productCode, "ProductName")) = _ LCase(ProductName) Then Exit For Next If IsEmpty(productCode) Then MsgBox "Business Portal is not installed." End If 'Look up the install location for the Business Portal BPLocation = installer.ProductInfo(productCode, "InstallLocation") 'Set up the locations that specify where to place things 'bin folder, as determined by the Registry key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Business Framework\" _ & "Install\BinInstallDir" BPBin = Sh.RegRead(key) 'map folder BPMap = BPBin + "map\" 'application folder BPApp = BPLocation + "Applications\" 'Find out where the various pieces were installed by looking 'at the CustomActionData property passed from the installer If(IsEmpty(Session)) Then 'Not running from within the installer. Get the source path based 'on the current folder. InstallLoc = sh.CurrentDirectory InstallLoc = Left(InstallLoc, InStr(InstallLoc, "\Scripts")) Else 'Running inside the installer, so use the CustomActionData InstallLoc = Session.Property("CustomActionData") End If 'Remove the MBF Packager items sh.Run Chr(34) & BPBin & "MbfPackager.exe" & Chr(34) & " " _ & "Import /P:" & Chr(34) & InstallLoc & "PackagerData/BPSDKRemove.project" _ & Chr(34) & " /I:Replace", 0, True 'Delete the business components from the Bin folder Set f = fso.GetFolder(InstallLoc & "Bin") Set fc = f.Files For Each f1 in fc 'Delete the item fso.DeleteFile(BPBin & f1.name) Next 'Delete the associations assembly Set f = fso.GetFolder(InstallLoc & "Associations") Set fc = f.Files For Each f1 in fc 'Delete the item fso.DeleteFile(BPBin & f1.name) Next 'Delete the items from the Map folder Set f = fso.GetFolder(InstallLoc & "Map") Set fc = f.Files For Each f1 in fc fso.DeleteFile(BPMap & f1.name) Next 'Remove the folders from Applications folder Set f = fso.GetFolder(InstallLoc & "Application") Set fc = f.SubFolders For Each f1 in fc fso.DeleteFolder(BPApp & f1.name) Next