Monday, May 2, 2011

GUIDE: dotNetInstaller - Free fast and easy installer for windows

In a nutshell
  1. Download dotNetInstaller: setup bootstrapper for Windows
    1. Great tutorials:
      1. http://www.codeproject.com/KB/install/dotNetInstaller.aspx
      2. http://code.dblock.org/ShowPost.aspx?Id=118
  2. Read this article if you're using 'Setup project using the Windows Installer'.
    1. http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/
  3. Read this article if you'r using 'Install shield limited edition'.
    1. http://blogs.msdn.com/b/somasegar/archive/2009/12/14/building-setup-and-deployment-packages-in-vs-2010.aspx
  4. If using MSI file...
    1. http://codefornothing.wordpress.com/2007/11/27/short-msi-tutorial/
    2. http://technet.microsoft.com/en-us/library/cc759262(WS.10).aspx
    3. http://www.advancedinstaller.com/user-guide/msiexec.html
    4. http://www.robvanderwoude.com/msiexec.php

Command line utilities for the job




REM Option Explicit

Dim exitcode : exitcode = 0

REM --- Functions ------------------------------------------------------------------


function readFromRegistry (strRegistryKey, strDefault )
    Dim value
 Dim objFSO, WSHShell

    On Error Resume Next
 Set objFSO   = CreateObject("Scripting.FileSystemObject")      
 Set WSHShell = CreateObject("Wscript.Shell")
    value = WSHShell.RegRead( strRegistryKey )

    if err.number <> 0 then
        readFromRegistry= strDefault
    else
        readFromRegistry=value
    end if

    set WSHShell = nothing
end function


function readDataFromMsiFile(file_path)
 Set objInstaller = CreateObject("WindowsInstaller.Installer")
 Set objProduct = objInstaller.SummaryInformation(file_path)
 Wscript.Echo "Code page: " &objProduct.Property(1)
 Wscript.Echo "Title: " & objProduct.Property(2)
 Wscript.Echo "Subject: " & objProduct.Property(3)
 Wscript.Echo "Author: " & objProduct.Property(4)
 Wscript.Echo "Keywords: " & objProduct.Property(5)
 Wscript.Echo "Comment: " & objProduct.Property(6)
 Wscript.Echo "Template: " & objProduct.Property(7)
 Wscript.Echo "Last Author: " & objProduct.Property(8)
 Wscript.Echo "Revision number: " & objProduct.Property(9)
 Wscript.Echo "Edit Time: " & objProduct.Property(10)
 Wscript.Echo "Last Printed: " & objProduct.Property(11)
 Wscript.Echo "Creation Date: " & objProduct.Property(12)
 Wscript.Echo "Last Saved: " & objProduct.Property(13)
 Wscript.Echo "Page Count: " & objProduct.Property(14)
 Wscript.Echo "Word Count: " & objProduct.Property(15)
 Wscript.Echo "Character Count: " & objProduct.Property(16)
 Wscript.Echo "Application Name: " & objProduct.Property(18)
 Wscript.Echo "Security: " & objProduct.Property(19)

 Set objProduct = Nothing
 Set objInstaller = Nothing

end function

function ProductVersion()
 ' SOURCE: http://stackoverflow.com/questions/815744/retrieving-version-of-an-msi-file-built-with-wix
 Dim installer, database, view, result

 Set installer = CreateObject("WindowsInstaller.Installer")
 Set database = installer.OpenDatabase (".\installer.msi", 0)

 Dim sumInfo  : Set sumInfo = installer.SummaryInformation(".\installer.msi", 0)
 sPackageCode =  sumInfo.Property(9) ' PID_REVNUMBER = 9, contains the package code.

 Set view = database.OpenView ("SELECT Value FROM Property WHERE Property='ProductVersion'")
    view.Execute
    Set result = view.Fetch
 
    ProductVersion = result.StringData(1)
end function
REM --- Code -------------------------------------------------------------------
new_version = ProductVersion()
installed_version = readFromRegistry ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{12345678-D8EF-4EE9-8DC4-FF5911256E0D}\DisplayVersion", "0.0.0" )
uninstall_user_result = MsgBox("About to install " + new_version + " instead of " + installed_version + ", continue?",3,"Please answer")


Select Case uninstall_user_result
 Case 6 ' Yes
  exitcode = 0
  
 Case Else
  exitcode = 1 
End Select

WScript.Quit exitcode  REM return results

Executing VBScripts from command line
Hope it helps.

No comments:

Post a Comment