Wednesday, December 17, 2014

Managed Installation - iTunes 12.0.1


**Please use Google Chrome for best viewing experience**

Follow these steps to deploy iTunes in your environment.
  1. Download iTunes & 7-Zip
  2. Using 7-Zip extract the executable contents. Of all those extracted MSI's you would only need 3 of them (See Fig:1).
    1. AppleApplicationSupport.msi; 2. AppleMobileDeviceSupport64.msi; 3. iTunes64.msi
    (Fig:1)
    3. Configuring "iTunes64.msi":  As a best practice never edit the vendor MSI, instead create a transform using MSI Transform Creator. Make sure to uncheck the boxes (See Fig: 2a). Now, edit the transform using any editor of your choice. In this tutorial I have used InstallShield to demonstrate the packaging process.
    Uncheck the boxes
    (Fig: 2a)
                                                                                                                               
    # Click on "Property Manager" under "Behavior & Logic": Edit/Add these properties.                                                                                                                                                                                                                                             REGSRCH_DESKTOP_SHORTCUTS = 0                                      REGSRCH_MEDIA_DEFAULTS = 0                                    IAcceptLicense = 0                                            DISABLEADVTSHORTCUTS = 0                                      SCHEDULE_ASUW = 0                                            ChkOptLaunchiTunes = 1                                        TARGETDIR = C:\                                              INSTALLDIR = C:\Program Files (x86)\iTunes\                  ITUNES_LANGID = 1033                                          DESKTOP_SHORTCUTS = 1                                        AMDS_IS_INSTALLED = 1                                        REENABLEAUTORUN = 0                                                NO_ASUW = 0                                                  NO_BONJOUR = 0                                                        REBOOT = ReallySuppress                                                                                                                                 # Click on "Direct Editor" under "Additional Tools":                                     > Search for "caPackage" table, Right-click on "AppleSoftwareUpdate" and select "Drop Row(s)" button. Do the same for "Bonjour" aswell (See Fig: 2b).
    caPackage - table
    (Fig: 2b)

    CheckBox - table
    (Fig: 3)

    > Search for "CheckBox" table and set all the values to zero (See Fig: 3).                                                             > Search for "LaunchCondition" table, right-click on "NOTBNEWERPRODUCTINSTALLED" and select "Drop Row(s)" (See Fig: 4)
    LaunchCondition - table
    (Fig: 4)
  3.                                                                                                                              > Search for "Component" table and look for "iTunesDesktopShortcuts" component. Set the condition DESKTOP_SHORTCUTS="0".
  4. Configuring "AppleMobileDeviceSupport64.msi": Follow the instructions as discussed in Step#3 to create a transform. Select the "Property Manager" listed under "Behavior and Logic".  Now set these values,                                              IAcceptLicense = Yes                                                                   INSTALLDIR = C:\Program Files (x86)\CommonFiles\Apple\Mobile Device Support\                                                            TARGETDIR = C:\                                                                                                                          Click on "Direct Editor" under "Additional Tools": Search for "LaunchCondition" table, right-click on "NOTBNEWERPRODUCTINSTALLED" and select "Drop Row(s)" (See Fig below).
      
  5. Now create a batch file to install these 3 MSI's in sequence.                              (a) AppleApplicationSupport.msi                                                                 (b) AppleMobileDeviceSupport64.msi & AppleMobileDeviceSupport64.mst       (c) iTunes64.msi & iTunes64.mst
  6. Launch the iTunes shortcut (Start > All Programs > iTunes > iTunes.lnk). 
  7. Click on "Agree" button on Agreement window
      
  8. Click "OK"
      
  9. Click "OK"
  10. On the welcome screen, click on "Agree"
  11. Click on the drop down menu (top corner left), and select "Preferences"
      
  12. Click on "Advanced" tab and uncheck "Check for new software upgrades automatically". 
  13. Close iTunes.
  14. Here comes the tricky part. Create a folder (Eg. Apple iTunes) and create two sub-folders (Local & Roaming). Under Roaming create another sub-folder "Preferences". Now copy these files onto respective folders that you have just created,             (a) %userprofile%\Appdata\Local\Apple Computer\iTunes\cache.db              (b) %userprofile%\Appdata\Local\Apple Computer\iTunes\iTunesPrefs.xml  (c) %userprofile%\AppData\Roaming\Apple Computer\iTunes\iTunesPrefs.xml                                                             (d) %userprofile%\AppData\Roaming\Apple Computer\iTunes\com.apple.iTunes.plist   (e) %userprofile%\AppData\Roaming\Apple Computer\iTunes\Preferences\com.apple.mediaaccessibility.plist              Note: The "iTunesPrefs.xml" files located in Local & Roaming are different though they share the same name. Do not mix it up.
  15. Copy this VBscript code onto notepad and name it "copyConfigFiles.vbs".                                                                                                                           'This script creates required folders under AppData and copies the files to it. 
    on error resume next
    Set oShell = CreateObject( "WScript.Shell" )
    userprofile=oShell.ExpandEnvironmentStrings("%USERPROFILE%")
    systemdrive=oShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set afile = fso.GetFile(systemdrive & "\ProgramData\Apple iTunes\local\cache.db")
    strDestination1 =userprofile & "\AppData\Local\Apple Computer\iTunes\cache.db"
    Set bfile = fso.GetFile(systemdrive & "\ProgramData\Apple iTunes\local\iTunesPrefs.xml")
    strDestination2 =userprofile & "\AppData\Local\Apple Computer\iTunes\iTunesPrefs.xml"
    Set cfile = fso.GetFile(systemdrive & "\ProgramData\Apple iTunes\Roaming\iTunesPrefs.xml")
    strDestination3 =userprofile & "\AppData\Roaming\Apple Computer\iTunes\iTunesPrefs.xml"
    Set dfile = fso.GetFile(systemdrive & "\ProgramData\Apple iTunes\Roaming\Preferences\com.apple.iTunes.plist")
    strDestination4 =userprofile & "\AppData\Roaming\Apple Computer\iTunes\Preferences\com.apple.iTunes.plist"
    Set efile = fso.GetFile(systemdrive & "\ProgramData\Apple iTunes\Roaming\Preferences\com.apple.mediaaccessibility.plist")
    strDestination5 =userprofile & "\AppData\Roaming\Apple Computer\iTunes\Preferences\com.apple.mediaaccessibility.plist"

    fso.CreateFolder(userprofile & "\AppData\Local\Apple Computer")
    fso.CreateFolder(userprofile & "\AppData\Local\Apple Computer\iTunes") 
    fso.CreateFolder(userprofile & "\AppData\Roaming\Apple Computer")
    fso.CreateFolder(userprofile & "\AppData\Roaming\Apple Computer\iTunes") 
    fso.CreateFolder(userprofile & "\AppData\Roaming\Apple Computer\iTunes\Preferences") 
    afile.Copy(strDestination1)
    bfile.Copy(strDestination2)
    cfile.Copy(strDestination3)
    dfile.Copy(strDestination4)
    efile.Copy(strDestination5)                                                                                                
  16. Now move this script to the folder you created before (Step14: Apple iTunes) .           
  17. Create another VBscript (Active Setup) that creates registry entries to run the "copyConfigFiles.vbs" from "%ProgramData%\Apple iTunes" directory. Name this file as "Apple_iTunes_ActiveSetup.vbs". Here is the code for it,                                                                                                                                     Dim strReturn : strReturn = 0
    Call Main()
    Sub Main()
    Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
    Dim objShell : Set objShell = CreateObject("WSCript.Shell")
    ' Set installation registry values for Apple_iTunes_12.0.1
    objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\Apple_iTunes_12.0.1\", "Apple_iTunes_12.0.1_R00", "REG_SZ"
      objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\Apple_iTunes_12.0.1\stubpath", "C:\Windows\System32\wscript.exe //b //nologo " & Chr(34) & objShell.ExpandEnvironmentStrings("%ProgramData%") & "\Apple iTunes\copyConfigFiles.vbs" & Chr(34), "REG_SZ"
    objShell.RegWrite "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\Apple_iTunes_12.0.1\version", "1", "REG_SZ"
    Set objFSO = Nothing
    Set objShell = Nothing
    End Sub
  18. Using InstallShield create a new MSI from scratch and name it (eg. iTunes Config). Click on "Installation Designer" tab and go to "Application Data" > "Files and Folders" > "Destination Computer" > Right click and select "Show Predefined Folder" > [CommonAppDataFolder]. Repeat the same and select [ProgramFilesFolder] as well.                                                                         # Copy the folder that you have created (Apple iTunes) and paste it under [CommonAppDataFolder].                                                                                 # Under [ProgramFilesFolder] create a folder and name it "iTunes Config". Copy the "Apple_iTunes_ActiveSetup.vbs" script to this directory.                     # Create a custom action to run "Apple_iTunes_ActiveSetup.vbs". Follow these steps to create custom action and build your MSI.

  19. Finally not the least, create a batch/VB script to run the MSI's in sequence. (a) AppleApplicationSupport.msi (b) AppleMobileDeviceSupport64.msi & AppleMobileDeviceSupport64.mst        (c) iTunes64.msi & iTunes64.mst                                 (d) iTunes Config.msi                                              Note: Your customization will only become effective once you LogOff and Log back in after the install. Yeah, you guessed it right, active setup needs to run to copy the files under current user AppData directory.
  20. Launch the iTunes shortcut and boom you're done.
    Expected Behavior: iTunes tends to self-heal when you happen to launch the shortcut. Please comment if anyone has a solution to get rid of this behavior.                                                                                                                           References:                                                                                                (i)  Re-Packaging Apple iTunes 10.6.1.7 and later                                             (ii) Advanced customization - Apple         

1 comment:

  1. Thanks to Rohit Thum! I got the solution to managed installation. I will visit your site to get more updates.

    ReplyDelete